竹園論壇

標題: Q12289 - One-Two-Three [打印本頁]

作者: HSCHE    時間: 2014-5-6 14:30
標題: Q12289 - One-Two-Three
本帖最後由 HSCHE 於 2014-5-6 14:32 編輯

你的弟弟剛學會寫英文的一二三。他在一張紙上寫了很多這幾個字,而你的工作便是辨認它們。要注意的是你弟弟不過是個小孩子,因此他會犯些小錯誤:至多一個錯誤的字母。單字長度一定是正確的。他所寫的一定是小寫字母,每個單字只可能有一種合理解釋。
Input
第一行包含你弟弟所寫單字數。接下來的每一行含有一個小寫字母組成的單字。單字必符合上述限制:至多一個錯誤的字母,但是單字長度永遠正確。輸入中最多有 10 個單字。

Output
對每筆測資,輸出單字的數值。
Sample Input
Sample Output
3
owe
too
theee

1
2
3



翻譯 by: zerojudge, snail


在此附上題目連結
UVA: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3710
LUCKY CAT: http://luckycat.kshs.kh.edu.tw/homework/q12289.htm
解題感想:這題算是簡單,但是小弟我因為第一次看錯題目,以及大量的BUG,各種WA,所以特PO此題
AC CODE:

這是神寫的:
#include<iostream>
  • #include<cstring>
  • using namespace std;


  • int main()
  • {
  •         int T;
  •         char in[10];
  •         (cin>>T).get();
  •         while(T--)
  •         {
  •                 cin.getline(in,10);
  •                 switch(strlen(in))
  •                 {
  •                 case 3: //one two six
  •                         if     (in[0]=='o'&&in[1]=='n'||in[0]=='o'&&in[2]=='e'||in[1]=='n'&&in[2]=='e')cout<<"1\n";
  •                         else if(in[0]=='t'&&in[1]=='w'||in[0]=='t'&&in[2]=='o'||in[1]=='w'&&in[2]=='o')cout<<"2\n";
  •                         else cout<<"6\n";
  •                         break;
  •                 case 4: //zero four five nine
  •                         if     (in[0]=='z'&&in[1]=='e'||in[0]=='z'&&in[2]=='r'||in[1]=='e'&&in[2]=='r')cout<<"0\n";
  •                         else if(in[1]=='o'&&in[2]=='u'||in[1]=='o'&&in[3]=='r'||in[2]=='u'&&in[3]=='r')cout<<"4\n";
  •                         else if(in[1]=='i'&&in[2]=='v'||in[1]=='i'&&in[3]=='e'||in[2]=='v'&&in[3]=='e')cout<<"5\n";
  •                         else cout<<"9\n";
  •                         break;
  •                 case 5: //three seven eight
  •                         if     (in[0]=='t'&&in[1]=='h'||in[0]=='t'&&in[2]=='r'||in[1]=='h'&&in[2]=='r')cout<<"3\n";
  •                         else if(in[0]=='s'&&in[1]=='e'||in[0]=='s'&&in[2]=='v'||in[1]=='e'&&in[2]=='v')cout<<"7\n";
  •                         else cout<<"8\n";
  •                         break;
  •                 }
  •         }

  •         return 0;
  • }

  • 這是小弟寫的:
    #include<iostream>
  • #include<cstdio>
  • #include<cstring>
  • #include<cmath>
  • #include<stack>
  • #include<vector>
  • using namespace std;
  • int main()
  • {
  •         int a,k=0;
  •         char d[100];
  •         cin>>a;
  •         while(a--)
  •         {
  •                 k=0;
  •                 scanf("%s",d);
  •                 if(strlen(d)==5)
  •                 {
  •                         cout<<"3\n";
  •                 }
  •                 if(strlen(d)==3)
  •                 {
  •                         if(d[0]!='o') k++;
  •                         if(d[1]!='n') k++;
  •                         if(d[2]!='e') k++;
  •                         if(k==1||k==0)
  •                         {
  •                                 cout<<"1\n";
  •                         }
  •                         if(k>1)
  •                         {
  •                                 cout<<"2\n";
  •                         }
  •                 }
  •         }
  • }







  • 歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2