解题思路:因为给定的数据是多组,所以我们只需要多次做加法就可以了,将上一次的和又作为下一次加法运算的一个加数。

反思:还是题意理解不够清楚,最开始以为只是算三个大数相加,后来才发现是多个,然后注意到当输入a的第一个字符为0的时候结束运算,输出结果。

 Integer Inquiry 

One of the firstusers of BIT's new supercomputer was Chip Diller. He extended his explorationof powers of 3 to go from 0 to 333 and he explored taking various sums of thosenumbers.

``Thissupercomputer is great,'' remarked Chip. ``I only wish Timothy were here to seethese results.'' (Chip moved to a new apartment, once one became available onthe third floor of the Lemon Sky apartments on Third Street.)

Input

The input willconsist of at most 100 lines of text, each of which contains a singleVeryLongInteger. Each VeryLongInteger will be 100 or fewer characters inlength, and will only contain digits (no VeryLongInteger will be negative).

The final inputline will contain a single zero on a line by itself.

Output

Your programshould output the sum of the VeryLongIntegers given in the input.

Sample Input

123456789012345678901234567890

123456789012345678901234567890

123456789012345678901234567890

0

Sample Output

370370367037037036703703703670

#include<stdio.h>
#include<string.h>
#define max 1000
void add(char a[],char b[],char c[])
{
char m[max],n[max];
int i;
int len1 ,len2;
int flag=0;
memset(m,0,sizeof(m));
memset(n,0,sizeof(n));
len1=strlen(a);
len2=strlen(b);
for(i=0;i<len1;i++)
{
m[i]=a[len1-i-1]-'0';
}
for(i=0;i<len2;i++)
{
n[i]=b[len2-i-1]-'0';
}
for(i=0;i<=len1||i<=len2;i++)
{
c[i]=m[i]+n[i]+flag;
flag=c[i]/10;
c[i]=c[i]%10+'0';
}
}
void shuchu(char c[])
{
int i,j;
int len;
len=strlen(c);
for(i=len-1;c[i]=='0';i--);
for(j=i;j>=0;j--)
{
printf("%c",c[j]);
}
printf("\n");
}
int main()
{
char a[max],b[max],c[max];
int i,j,len,tag=1;
memset(b,0,sizeof(b));
for(j=1;j<200&&tag;j++)
{
scanf("%s",&a);
if(a[0]=='0')
tag=0;
memset(c,0,sizeof(c));
add(a,b,c);
len=strlen(c);
for(i=0;i<len;i++)
{
b[i]=c[len-i-1];
}
}
shuchu(c); }

  

最新文章

  1. vs多项目模板及add-in开发
  2. Ext.NET 4.1 最新版本破解
  3. Dancing Links初学记
  4. 社交APP经典死法18种,听野路子产品菜狗怎么说
  5. winForm 打印预览
  6. smarty模板的基础搭建
  7. 【转】四种常见的POST提交数据方式
  8. java -jdk配置1(环境变量配置)
  9. 从头开始学JavaScript (九)——执行环境和作用域
  10. .NET基础——运算符
  11. thinkphp3.2.3的使用心得之i方法(零)
  12. Codeforces555 B. Case of Fugitive
  13. WCF-Oracel适配器针对UDT的使用配置与注意事项
  14. Android 开发 框架系列 百度语音合成
  15. 8.1Python面向对象编程(一)
  16. 使用Nginx+Lua实现自定义WAF
  17. Spring Boot 添加JSP支持【转】
  18. HTML5和CSS3扁平化风格博客(基础篇)
  19. Python int() 函数
  20. java unsupported major.minor version 51.0 解决

热门文章

  1. 02--linux操作系统基础学习笔记
  2. 【前端】CSS隐藏元素的方法和区别
  3. jmeter目录讲解
  4. 算法18-----判断是否存在符合条件的元素【list】
  5. Project Euler 30 Digit fifth powers
  6. HDU1241 - Oil Deposits【DFS】
  7. P1423 小玉在游泳
  8. nyoj303-序号交换
  9. PyCharm中导入MySQLDB模块小结
  10. Nginx 安装配置证书,设置HTTPS站点