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

反思:还是题意理解不够清楚,最开始以为只是算三个大数相加,后来才发现是多个,然后注意到当输入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. "国学"能带给孩子什么?

       您是家长吗?   是!就点标题下方蓝色的 静心坊 三字,然后点关注!您就可以享受到我们为您提供的最新教育信息. 读国学,除大量识字之外,还能带给孩子什么呢? 男孩子读国学,国学能教会他做一个正直 ...

  2. C# word生成html

    引入 Aspose.Words public void ConvertToHtml(string wordPath, string savaPath) { try { Aspose.Words.Doc ...

  3. jmeter搭建

    jdk 1.8的地址  链接:https://pan.baidu.com/s/1eEyYbzo1Tfbvbmf_vN2yUA 密码:6dxi 1.安装JDK 选择安装目录 安装过程中会出现两次 安装提 ...

  4. SLAB

    slab:由于内核会有许多小对象,这些对象构造销毁十分频繁,比如i-node,dentry,这些对象如果每次构建的时候就向内存要一个页(4kb),而其实只有几个字节,这样就会非常浪费,为了解决这个问题 ...

  5. wamp的安装配置

    WAMP是指在Windows服务器上使用Apache.MySQL和PHP的集成安装环境,可以快速安装配置Web服务器. 一.下载安装包 进入官网下载:http://www.wampserver.com ...

  6. Oracle 知识积累

    1.oracle存储过程中is和as的区别 在存储过程(PROCEDURE)和函数(FUNCTION)中没有区别,在视图(VIEW)中只能用AS不能用IS,在游标(CURSOR)中只能用IS不能用AS ...

  7. 洛谷—— P1238 走迷宫

    https://www.luogu.org/problem/show?pid=1238 题目描述 有一个m*n格的迷宫(表示有m行.n列),其中有可走的也有不可走的,如果用1表示可以走,0表示不可以走 ...

  8. Python Study (01) 之 特殊方法

    Python深入:特殊方法和多范式 Python是一切皆对象,意思就是python的天生就是个"纯面向对象语言"呀. 但是!!! Python还是一个多范式语言(multi-par ...

  9. rails new app的时候设置skip-bundle

    rails new app的时候设置skip-bundle rails new app --skip-bundle 这样可以越过bundle install阶段:

  10. hibernate 管理 Session(单独使用session,非spring)

    Hibernate 自身提供了三种管理 Session 对象的方法 Session 对象的生命周期与本地线程绑定 Session 对象的生命周期与 JTA 事务绑定 Hibernate 托付程序管理 ...