标签:lse turn == cas fclose define max include cst
AC代码:
#include <iostream> #include <cstdio> #include <cstring> #define Max 1050 using namespace std; void hanshu(char *s1,char *s2,char *s); int main(void) { freopen("in.txt","r",stdin); int T,count=0; char s1[Max],s2[Max],s[Max]; scanf("%d",&T); while(T--) { scanf("%s%s",s1,s2); hanshu(s1,s2,s); count++; if(T!=0) printf("Case %d:\n%s + %s = %s\n\n",count,s1,s2,s); else printf("Case %d:\n%s + %s = %s\n",count,s1,s2,s); } fclose(stdin); return 0; } void hanshu(char *s1,char*s2,char *s) { int length1=strlen(s1),length2=strlen(s2),length; if(length1>length2) length=length1; else length=length2; s[length+1]=‘\0‘; s[0]=‘0‘; int a=0,i; for(i=length;length1&&length2;i--) { a=(s1[--length1]-‘0‘)+(s2[--length2]-‘0‘)+a/10; s[i]=a%10+‘0‘; } while(length1) { a=(s1[--length1]-‘0‘)+a/10; s[i--]=a%10+‘0‘; } while(length2) { a=(s2[--length2]-‘0‘)+a/10; s[i--]=a%10+‘0‘; } s[i]=a/10+‘0‘; int t=0; while(s[t]==‘0‘&&t<length) t++; strcpy(s,s+t); }
标签:lse turn == cas fclose define max include cst
原文地址:https://www.cnblogs.com/phaLQ/p/10031621.html