ZeroJudge A466: One-Two-Three

UVa 12289 – One-Two-Three

Your younger brother just learned to write the English numbers one, two, and three. He wrote them many times on a piece of paper, and your job is to identify them.

You should note that your younger brother is just a kid, so he might make some small mistakes:

  • At most one wrong letter.
  • The length of the word will always be correct.
  • He will definitely write in lowercase letters.
  • Each word may only have one valid interpretation.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The first line contains the number of words your brother wrote. Each of the following lines contains a word composed of lowercase letters. The words must adhere to the aforementioned restrictions: at most one incorrect letter, but the length of each word is always correct. There will be at most 10 words in the input.For each test case, output the numerical value of the word.
3
owe
too
theee
1
2
3

Thought Process

For the answer "Three," you can directly check if the string length is 5 and output accordingly. As for the remaining two words, there are only 6 possible combinations. You can write these six combinations as if statements to handle each case.

Sample Code-ZeroJudge A466: One-Two-Three

#include <iostream>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    for (int i = 0; i<N; i++)
    {
        string str;
        cin >> str;
        if (str.length() == 5) cout << 3 << "\n";
        else
        {
            if (str[0] == 'o' && str[1] == 'n') cout << 1 << "\n";
            else if (str[1] == 'n' && str[2] == 'e') cout << 1 << "\n";
            else if (str[2] == 'e' && str[0] == 'o') cout << 1 << "\n";
            if (str[0] == 't' && str[1] == 'w') cout << 2 << "\n";
            else if (str[1] == 'w' && str[2] == 'o') cout << 2 << "\n";
            else if (str[2] == 'o' && str[0] == 't') cout << 2 << "\n";
        }
    }
}

//ZeroJudge A466
//Dr. SeanXD

Comments