one + two = three four + five six = zero seven + eight nine = zero + zero =
3 90 96
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; int main() { int i,j,k; int t,n,m; int a,b,bj; char liu[100]; char zm[16][6]={"zero","one","two","three","four","five","six","seven","eight","nine"}; char cs[6]; while(1) { memset(cs,0,strlen(cs)); gets(liu); if(liu[0]==‘z‘&&liu[7]==‘z‘) break; for(i=0;i<strlen(liu);i++) ///find ‘+‘; if(liu[i]==‘+‘) { bj=i; break; } a=0; for(i=0;i<bj;i++) { if(liu[i]==‘ ‘) { for(j=0;j<i;j++) ///提取string { cs[j]=liu[j]; } cs[j]=‘\0‘; for(k=0;k<10;k++) if(strcmp(cs,zm[k])==0) a=k; memset(cs,0,strlen(cs)); if(liu[i+1]!=‘+‘) { k=0; for(j=i+1;j<bj-1;j++) cs[k++]=liu[j]; for(j=0;j<10;j++) if(strcmp(cs,zm[j])==0) a=a*10+j; } break; } } memset(cs,0,strlen(cs)); b=0; for(i=bj+2;i<strlen(liu);i++) ///确定a; { if(liu[i]==‘ ‘) { k=0; for(j=bj+2;j<i;j++) ///提取string { cs[k++]=liu[j]; } cs[k]=‘\0‘; for(k=0;k<10;k++) if(strcmp(cs,zm[k])==0) b=k; memset(cs,0,strlen(cs)); if(liu[i+1]!=‘=‘) { k=0; for(j=i+1;j<strlen(liu)-1;j++) cs[k++]=liu[j]; cs[k-1]=‘\0‘; for(j=0;j<10;j++) if(strcmp(cs,zm[j])==0) b=b*10+j; } break; } } printf("%d\n",a+b); } return 0; }
A + B------HDOJ杭电1228(读取字符串练基础),布布扣,bubuko.com
A + B------HDOJ杭电1228(读取字符串练基础)
原文地址:http://blog.csdn.net/u014231159/article/details/25833335