This is an A+B Problem

逃离我推掉我的手 2022-08-10 08:48 141阅读 0赞

This is an A+B Problem

Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^

题目描述

As usual, there will be an A+B problem in warming up, this problem is:
Given two integers A and B, your job is to calculate the sum of A + B.

输入

Th ere are several test cases, For each test case:
There are two integers A, B for each case (0 ≤ A , B < 101000).

输出

For each test case, output one line containing the result of A+B.

示例输入

  1. 1 2
  2. 11111111111 11111111111

示例输出

  1. 3
  2. 22222222222

提示

来源

示例程序

  1. #include<stdio.h>
  2. #include<string.h>
  3. char a[2000],b[2000],c[2000];
  4. int main()
  5. {
  6. int i,j,n,m,k,t,l;
  7. memset(a,0,sizeof(a));
  8. memset(b,0,sizeof(b));
  9. while(scanf("%s %s",a,b)!=EOF)
  10. {
  11. memset(c,0,sizeof(c));
  12. n=strlen(a);
  13. m=strlen(b);
  14. l=0;
  15. //printf("%s %s\n",a,b);
  16. for(i=n-1,j=m-1;j>=0&&i>=0;i--,j--)
  17. c[l++]=a[i]+b[j]-48;
  18. if(i!=-1)
  19. for(;i>=0;)
  20. c[l++]=a[i--];
  21. if(j!=-1)
  22. for(;j>=0;)
  23. c[l++]=b[j--];
  24. //if(c[l-1]>=58)
  25. //l++;
  26. for(k=0;k<l;k++)
  27. if(c[k]>=58)
  28. {
  29. c[k]=c[k]-10;
  30. c[k+1]+=1;
  31. }
  32. if(c[k]!=0)
  33. {
  34. printf("%c",c[k]+48);
  35. }
  36. for(t=l-1;t>=0;t--)
  37. printf("%c",c[t]);
  38. printf("\n");
  39. }
  40. }

发表评论

表情:
评论列表 (有 0 条评论,141人围观)

还没有评论,来说两句吧...

相关阅读