您的位置:首页 > 其它

UVa 12289 - One-Two-Three

2014-07-27 23:14 363 查看
题目:你有你哥弟弟,他会写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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: