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

反思:还是题意理解不够清楚,最开始以为只是算三个大数相加,后来才发现是多个,然后注意到当输入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. Js中判断变量存不存在的问题

    前面写过jquery对象存在与否的判断.现在谈下Js中判断变量存不存在的问题. 如果这样if(!a),当变量a在js中没有申明时,就会报错,那么接下去的代码将不会被执行.注意,这种判断只要变量申明过, ...

  2. trigger事件就是继承某一个类的事件.

    <html><head><script type="text/javascript" src="/jquery/jquery.js" ...

  3. idea使用lombok

    1.这玩意可以帮助我们自动实现set.get方法,实现过程有两处,只要理解了这两处,对其实际工作如何使用就非常简单了 2.第一点就是编译过程,比如使用gradle build 等编译工具进行编译时,会 ...

  4. iview关于menu结合router问题

    #iview关于menu结合router问题 1. Menu.Item下router问题: 直接在Menu标签上绑定on-select事件,可以获取到name(name为元素绑定name) <M ...

  5. 原生js模拟双色球

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  6. -2 caffe数据结构

    一.Blob 使用: 访问数据元素: 计算diff: 保存数据与读取数据: 二.Layer 三.Net

  7. 【Tool】Mac环境维护

    1. 安装编译opencv https://blog.csdn.net/lijiang1991/article/details/50756065 /Users/yuhua.cheng/Opt/open ...

  8. js里写html代码 啥时候要用“\"转义

    当去掉\的时候 字体变黑 需要加\

  9. CountDownLatch使用方法

    CountDownLatch是一个同步辅助类,在完毕一组正在其它线程中运行的操作之前.它同意一个或多个线程一直等待. 如果我们周末要去旅游.出游前须要提前订好机票.巴士和酒店,都订好后就能够出发了.这 ...

  10. 機器學習基石 机器学习基石 (Machine Learining Foundations) 作业2 Q16-18 C++实现

    大家好,我是Mac Jiang,今天和大家分享Coursera-NTU-機器學習基石(Machine Learning Foundations)-作业2 Q16-18的C++实现.尽管有非常多大神已经 ...