#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<string> #include<cctype> #include<stack> #include<queue> #include<vector> #include<map> #include<set> #include<sstream> #include<utility> #include<math.h> #include<stdio.h> #include<ctype.h> #define M 110 using namespace std; int strLen(char[]); void strRev(char[]); void longAdd(char[],char[]); int main() { char num[M],res[M]; memset(res,'\0',M); //freopen("in.txt","r",stdin); while(gets(num)) { strRev(num); longAdd(res,num); memset(num,'\0',M); } strRev(res); printf("%s\n",res); return 0; } void longAdd(char res[],char num[]) { int i,a,b,c=0; for(i=0;res[i]||num[i];i++) { a=res[i]?res[i]-48:0; b=num[i]?num[i]-48:0; res[i]=(a+b+c)%10+48; c=(a+b+c)/10; } if(c) res[i]=c+48; } int strLen(char str[]) { int i; for(i=0;str[i];i++); return(i); } void strRev(char str[]) { int i,len=strLen(str),n=len/2; char ch; for(i=0;i<n;i++) { ch=str[i]; str[i]=str[len-i-1]; str[len-i-1]=ch; } }
Saturday, 1 October 2011
ACM 424- Integer Inquiry
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment