题目:你有你哥弟弟,他会写one、two、three这3个单词,不过可能会写错一个字母,输出对应的数字。
分析:简单题。分别和3个单词比较,统计错误走个数,直接输出错误数不大于1的即可。
说明:uhunt终于好用了,O(∩_∩)O~
#include <iostream>
#include <cstdlib>
using namespace std;
char map[3][6] = {"one","two","three"};
char buf[6];
int main()
{
int n;
while ( cin >> n )
while ( n -- ) {
cin >> buf;
for ( int i = 0 ; i < 3 ; ++ i ) {
int count = 0;
for ( int j = 0 ; buf[j] && map[i][j] ; ++ j )
count += (buf[j] != map[i][j]);
if ( count <= 1 ) cout << i+1 << endl;
}
}
return 0;
}