杭电1228
2014-03-26 17:00
155 查看
这题没有什么水平,但是我没有找到比较好或者是比较巧妙的处理的方法,基本上的AC的答案的思路都是差不多的,但是也有处理的比较好的,这里呢我就不再讲解思路了,因为这个大家可以想出很多的做法,下面就是贴两个别人的比较好可以AC的代码:
代马一:
代马一:
#include <stdio.h> #include <string.h> char num[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"}; int search(char ch[]) { int i; for(i=0;i<10;i++) { if(strcmp(ch,num[i])==0) break; } return i; } int main() { char count[10]; int a,b; while(1) { a=0; while(scanf("%s",count)&&strcmp(count,"+")!=0) a=a*10+search(count); b=0; while(scanf("%s",count)&&strcmp(count,"=")!=0) b=b*10+search(count); if(a==0&&b==0) return 0; else { printf("%d\n",a+b); } } return 0; }
代码二:
#include <stdio.h> #include <string.h> char *wdvalue[]={"zero","one","two","three", "four","five","six","seven","eight","nine"}; int search(char s[]) { int i; for(i=0;i<10&&strcmp(s,wdvalue[i]);i++) ; return i; } main() { char s[100]; int sum,a; sum=a=0; while(scanf("%s",s)!=EOF){ if(!strcmp(s,"=")){ sum+=a; if(sum==0) break; printf("%d\n",sum); sum=a=0; }else if(!strcmp(s,"+")){ sum+=a; a=0; }else a=a*10+search(s); } return 0; }
相关文章推荐
- 杭电1228
- A + B(杭电1228)
- 杭电1228
- strcmp函数 杭电-1228
- 杭电1228
- 杭电 ACM 1228 A+B
- 杭电OJ 1228 A + B
- 杭电ACM 1228 A + B
- 【水题+字符串】杭电 hdu 1228 A + B
- 杭电1228 A+B
- 杭电OJ——1228 A+B
- 杭电1228 A+B(英文版)
- 杭电oj-1228-A+B
- 【杭电】[1228]A + B
- 杭电1228 A +B
- 杭电ACM--1228 A+B
- 杭电ACM1068(二分图)
- 杭电ACM2011-- 多项式求和
- 杭电oj2023 c++
- 杭电2579-Dating with girls(2) (非常清晰易懂的代码)