12289 - One-Two-Three
Time limit: 1.000 seconds
Your little brother has just learnt to write one, two and three, in English. He has written a lot of those words in a paper, your task is to recognize them. Note that your little brother is only a child, so he may make small mistakes: for each word, there might be at most one wrong letter. The word length is always correct. It is guaranteed that each letter he wrote is in lower-case, and each word he wrote has a unique interpretation.
Input
The first line contains the number of words that your little brother has written. Each of the following lines contains a single word with all letters in lower-case. The words satisfy the constraints above: at most one letter might be wrong, but the word length is always correct. There will be at most 10 words in the input.Output
For each test case, print the numerical value of the word.Sample Input
3 owe too theee
Sample Output
1 2 3
这居然还是lrj出的题。。
完整代码:
/*0.016s*/
#include<cstdio>
#include<cstring>
const char one[] = "one";
char s[10];
int main()
{
int t, i, c;
scanf("%d\n", &t);
while (t--)
{
gets(s);
if (strlen(s) == 5) puts("3");
else
{
c = 0;
for (i = 0; i < 3; ++i) if (s[i] == one[i]) ++c;
puts(c > 1 ? "1" : "2");
}
}
return 0;
}
本文介绍了一个简单的算法,用于识别小弟弟手写的一到三个英文单词,并将其转换为数字。该算法考虑到了儿童可能犯的小错误,如拼写错误等,并提供了一种有效的方法来解析这些单词。
145

被折叠的 条评论
为什么被折叠?



