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

反思:还是题意理解不够清楚,最开始以为只是算三个大数相加,后来才发现是多个,然后注意到当输入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); }

  

UVa 424 Integer Inquiry 【大数相加】的更多相关文章

  1. hdu acm-1047 Integer Inquiry(大数相加)

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. POJ 1503 Integer Inquiry(大数相加,java)

    题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...

  3. UVa 424 Integer Inquiry

    之前杭电上也做过a + b的高精度的题,不过这道题的区别是有多组数据. 之前做的时候开了3个字符数组a,b,c,在计算的时候还要比较a,b长度,短的那个还要加'0',还设置了一个add来存放进位. 现 ...

  4. POJ 1503 Integer Inquiry(大数相加)

    一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...

  5. HDU 1047 Integer Inquiry 大数相加 string解法

    本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...

  6. Integer Inquiry(大数相加)

    Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his explo ...

  7. 424 - Integer Inquiry

     Integer Inquiry  One of the first users of BIT's new supercomputer was Chip Diller. He extended his ...

  8. Integer Inquiry 大数加法

    Integer Inquiry 1 import java.util.*; 2 import java.math.*; 3 import java.io.*; 4 import java.text.* ...

  9. POJ 1503 Integer Inquiry 大数 难度:0

    题目链接:http://poj.org/problem?id=1503 import java.io.*; import java.math.BigInteger; import java.util. ...

随机推荐

  1. Jquery中拿到相同的对应的所有的标签

    在Jquery中相同的ID号不能用$()获得,即使是$().each()也不能获得所有的ID相同的元素,只能获得第一个匹配的元素. 比如: 以上4个div,如果用$("#jevoly&quo ...

  2. Visual Studio 2015中 安卓环境 cannot find adb.exe in specified sdk path

    安装完成后 发现 C:\Program Files (x86)\Android\android-sdk\platforms 是空的,用SDK Manager进行安装时发现 它需要往C:\Program ...

  3. jmeter出现乱码怎么解决

    本文是抄袭安大叔的性能    如果想在性能获得更好的发展  请添加公众号:测试那点事  大叔的群号:435092293  大叔曾经担任百度技术总监  很牛逼  相信大叔知道了不会怪我  毕竟我是你的学 ...

  4. Python笔记18-----函数收集参数

    1.收集参数(参数前面加*): def test1(param1,*params): print(param1) print(params) 调用:test1(1,2,3,4) 结果:1 (2,3,4 ...

  5. 【JavaScript框架封装】实现一个类似于JQuery的属性框架的封装

    // 属性框架 (function (xframe) { // 需要参与链式访问的(必须使用prototype的方式来给对象扩充方法) xframe.extend({ /** * 获取/设置某一个元素 ...

  6. 洛谷P1427 小鱼的数字游戏

    题目描述 小鱼最近被要求参加一个数字游戏,要求它把看到的一串数字(长度不一定,以0结束,最多不超过100个,数字不超过2^32-1),记住了然后反着念出来(表示结束的数字0就不要念出来了).这对小鱼的 ...

  7. Warning: The following processes: -cmd.exe -java.exe are locking the following directory:

  8. 说说sys_context函数

    select SYS_CONTEXT('USERENV', 'TERMINAL') terminal,        SYS_CONTEXT('USERENV', 'LANGUAGE') langua ...

  9. BA-siemens-apogee自适应控制

    简介 APOGEE楼控系统的控制器中,包括了由 Cybosoft开发的基于无模型自适应控制技术的自适应控制. 自适应控制是一个复杂的闭环循环控制算 法.自适应控制能自动校正参数以补偿机械的系 统/负载 ...

  10. getColor()方法过时的替代方法

    Android SDK 升級到 23 之後,getResource.getColor(R.color.color_name) 過時 使用新加入的方法 ContextCompat.getColor(co ...