啥子都不说,直接上代码
:
#include<stdio.h> #include<string.h> int MAX(int a,int b) { if(a>b) return a; return b; } void turn(char *p,char *q) { char t=*p; *p=*q; *q=t; } void change(char a[],int n) { int head=0,tail=n; while(head<tail){ turn(a+head,a+tail); tail--; head++; } } int main() { char digit1[1010],digit2[1010],digit3[1010]; while(scanf("%s%s",digit1,digit2)!=EOF){ memset(digit1+strlen(digit1)+1,‘0‘,sizeof(digit1)-strlen(digit1)); memset(digit2+strlen(digit2)+1,‘0‘,sizeof(digit2)-strlen(digit2)); memset(digit3,‘0‘,sizeof(digit3)); int i,len1,len2,len3; len1=1000; while(digit1[len1]==‘0‘&&len1>1){ len1--; } change(digit1,len1); len2=1000; while(digit2[len2]==‘0‘&&len2>1) len2--; change(digit2,len2); for(i=0;i<=MAX(len1,len2);i++) { digit3[i]=digit3[i]+digit1[i]+digit2[i]-‘0‘-‘0‘; if(digit3[i]>=‘0‘+10){ digit3[i+1]++; digit3[i]-=10; } } len3=1001; while(digit3[len3]==‘0‘&&len3>1) len3--; //printf("%d\n",len3); for(i=len3;i>0;i--) printf("%c",digit3[i]); printf("\n"); } return 0; }
时间: 2024-10-26 10:30:37