Dictionary Codeforces Solution | Codeforces Problem Solution 2022
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.
The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word comes earlier than word in the dictionary if one of the following conditions hold:
- the first letter of is less than the first letter of ;
- the first letters of and are the same, and the second letter of is less than the second letter of .
So, the dictionary looks like that:
- Word : ab
- Word : ac
- ...
- Word : az
- Word : ba
- Word : bc
- ...
- Word : zx
- Word : zy
You are given a word from the Berland language. Your task is to find its index in the dictionary.
The first line contains one integer () — the number of test cases.
Each test case consists of one line containing — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
No comments:
Post a Comment