Symbol
Limits: 2 sec., 512 MiB
This statement was translated automatically from Ukrainian.
Schoolchild, do you know the English alphabet by heart? If not — it’s
okay, we will remind you. Here are the uppercase letters of the
alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ. And here are the
lowercase ones: abcdefghijklmnopqrstuvwxyz.
You are given a single character, which is an uppercase or lowercase
English alphabet letter, a digit (one of 0123456789), or
one of the symbols
!@#$%&*()_-+=[]{};:/?.>,<~.
If the character is a lowercase or uppercase letter, output its ordinal number in the English alphabet.
If the character is a digit, output
digit.If the character is neither a letter nor a digit, output
weird symbol.
Input
A single character is given in one line.
Output
Output the answer depending on the given character.
You should output to the standard output stream (console). Your
output must strictly match the requirements of the problem. No extra
data should be outputted. For example, if you output something like
Enter c: before reading the character, or
Answer for the problem: before outputting the answer, you
will receive the Wrong Answer verdict.
Constraints
The character can be a lowercase or uppercase English alphabet letter, a digit, or a special symbol specified in the statement.
Evaluation consists of the following blocks:
1 point for each sample test from the statement,
10 points: the character is a lowercase letter,
10 points: the character is an uppercase letter,
20 points: the character is a letter,
4 points: the character is a digit,
4 points: the character is a special symbol,
20 points: the character is a letter or a digit,
28 points: no additional constraints.
You will receive the points for a block only if your program passes all tests in that block.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| d | 4 |
| Input (stdin) | Output (stdout) |
|---|---|
| G | 7 |
| Input (stdin) | Output (stdout) |
|---|---|
| 7 | digit |
| Input (stdin) | Output (stdout) |
|---|---|
| @ | weird symbol |
Notes
The character d is a lowercase letter. This letter is
the fourth in the alphabet.
The letter G is the seventh in the alphabet.
The character 7 is a digit.
The character @, which is called "at", snail, puppy, or
doggy, is neither a letter nor a digit.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
Symbol - Editorial
In this problem we had to write several checks to determine the
properties of the given character. To check whether a character is a
letter of the English alphabet, we can use built-in functions or
methods. For example, in C++ this is the function isalpha,
and in Python the method isalpha. To tell uppercase and
lowercase letters apart, we can use isupper and
islower in C++ or the corresponding methods in Python. We
can also check whether the character is in a range, for example
if (’a’ <= ch and ch <= ’z’) for lowercase letters
and if (’A’ <= ch and ch <= ’Z’) for uppercase
ones.
To find the position of a letter in the alphabet, it is convenient to
use how characters are encoded in a computer. Every character has its
own code, the ASCII code. For example, the uppercase letter
A has ASCII code \(65\),
the letter B has code \(66\), ..., the letter Z has
code \(90\). Lowercase letters have
their own codes too: a is \(97\), b is \(98\), ..., z is \(122\). There is no need to memorize the
codes of all letters: it is enough to know that the uppercase letters in
alphabetical order from A to Z have
consecutive codes. The same holds for lowercase letters: in alphabetical
order from a to z they also have consecutive
codes.
ASCII codes make it easy to compute the position of any letter in the
alphabet. For an uppercase letter, subtract the code of A
from its code and add one. For a lowercase letter, subtract the code of
a from its code and add one.
In C++ this is c - ’A’ + 1 for an uppercase letter and
c - ’a’ + 1 for a lowercase one.
In Python, ord(c) - ord(’A’) + 1 or
ord(c) - ord(’a’) + 1.
If the character is not a letter, we need to check whether it is a
digit. For this we can use the function isdigit in C++ or
the method isdigit in Python. Alternatively, we can check
whether the character is in the range from ’0’ to
’9’ with the condition
if (’0’ <= ch and ch <= ’9’).
If the character is neither a letter nor a digit, it is a special
character. In this case we print weird symbol.
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|