PAT:1016. 部分A+B (15) AC

当做字符串处理
#include<stdio.h> #include<string.h> int main() { char A[120],B[120],ca,cb; int iA=0,iB=0; scanf("%s %c %s %c",A,&ca,B,&cb); int lenA=strlen(A),lenB=strlen(B); int addA=0,addB=0; while(lenA!=-1)              //遍历每一位,是目标数就处理 { int tmp=ca-'0';             //将字符变成能加减的数字 if(A[lenA]==ca) addA=addA*10+tmp; --lenA; } while(lenB!=-1)               { int tmp=cb-'0'; if(B[lenB]==cb) addB=addB*10+tmp; --lenB; } printf("%d\n",addA+addB); return 0; }
posted on 2015-02-14 16:41  Evence  阅读(114)  评论(0编辑  收藏  举报