一二三(The Seventh Hunan Collegiate Programming Contest)
一二三
你弟弟刚刚学会写英语的一(one)、二(two)和三(three)。他在纸上写了好些一二三,可惜有些字母写错了。已知每个单词最多有一个字母写错了(单词长度肯定不会错),你能认出他写的啥吗?
输入
第一行为单词的个数(不超过10)。以下每行为一个单词,单词长度正确,且最多有一个字母写错。所有字母都是小写的。
输出
对于每组测试数据,输出一行,即该单词的阿拉伯数字。输入保证只有一种理解方式。
样例输入
3
owe
too
theee
样例输出
1
2
3
分析:此题就是一一对比字符串的符合,因为只有三种情况,前两种都是三位,所以一起比较,最后一个单独比较,直接比较,计一个临时变量就可
代码:
#include<iostream> #include<string.h> using namespace std; int main(){ char s[10]; string s1="one"; string s2="two"; string s3="three"; int T; int i,j; cin>>T; while(T--){ int len; int temp1=0,temp2=0,temp3=0; cin>>s; len=strlen(s); if(len==3){ for(i=0;i<3;i++){ if(s[i]==s1[i]){temp1++;} if(s[i]==s2[i]){temp2++;} } if(temp1>=2){cout<<"1"<<endl;} if(temp2>=2){cout<<"2"<<endl;} } if(len==5){ for(j=0;j<5;j++){ if(s[j]==s3[j]){temp3++;} } if(temp3>=4){cout<<"3"<<endl;} } } return 0; }