CSU 1100: 一二三

来源:互联网 发布:swagger codegen java 编辑:程序博客网 时间:2024/04/29 07:14

题目:

Description

你弟弟刚刚学会写英语的一(one)、二(two)和三(three)。他在纸上写了好些一二三,可惜有些字母写错了。已知每个单词最多有一个字母写错了(单词长度肯定不会错),你能认出他写的啥吗?  

Input

第一行为单词的个数(不超过10)。以下每行为一个单词,单词长度正确,且最多有一个字母写错。所有字母都是小写的。 

Output

对于每组测试数据,输出一行,即该单词的阿拉伯数字。输入保证只有一种理解方式。 

Sample Input

3owetootheee

Sample Output

123

有个类似的题目我的博客,不过要复杂多了

这个题目其实也差不多,只不过因为字典是固定的,而且只有3个单词,所以可以用特殊的方法来写。

代码:

#include<iostream>#include<string>using namespace std; int main(){    string s;    int n;    cin >> n;    for(int i = 0; i < n; i++)    {        cin >> s;        if(s.length() == 5)cout << 3 ;        else if (s[0] == 'o')        {            if(s[1] == 'w'&& s[2] == 'o')cout << 2;            elsecout << 1;        }        else        {            if(s[1] == 'n'&& s[2] == 'e')cout << 1;            else cout << 2;        }        cout << endl;    }    return 0;}

2 0
原创粉丝点击