UVa 424 Integer Inquiry 【大数相加】
解题思路:因为给定的数据是多组,所以我们只需要多次做加法就可以了,将上一次的和又作为下一次加法运算的一个加数。
反思:还是题意理解不够清楚,最开始以为只是算三个大数相加,后来才发现是多个,然后注意到当输入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 【大数相加】的更多相关文章
- hdu acm-1047 Integer Inquiry(大数相加)
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- POJ 1503 Integer Inquiry(大数相加,java)
题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...
- UVa 424 Integer Inquiry
之前杭电上也做过a + b的高精度的题,不过这道题的区别是有多组数据. 之前做的时候开了3个字符数组a,b,c,在计算的时候还要比较a,b长度,短的那个还要加'0',还设置了一个add来存放进位. 现 ...
- POJ 1503 Integer Inquiry(大数相加)
一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...
- HDU 1047 Integer Inquiry 大数相加 string解法
本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...
- Integer Inquiry(大数相加)
Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his explo ...
- 424 - Integer Inquiry
Integer Inquiry One of the first users of BIT's new supercomputer was Chip Diller. He extended his ...
- Integer Inquiry 大数加法
Integer Inquiry 1 import java.util.*; 2 import java.math.*; 3 import java.io.*; 4 import java.text.* ...
- POJ 1503 Integer Inquiry 大数 难度:0
题目链接:http://poj.org/problem?id=1503 import java.io.*; import java.math.BigInteger; import java.util. ...
随机推荐
- 使用序列号激活优动漫PAINT(附激活码)
优动漫PAINT是一款功能强大的动漫绘图软件,简单的中文界面和丰富的笔刷操纵,再次为设计工作者带来非一般的感受!最近,有不少小伙伴提出这样的疑问:购买安装优动漫PAINT之后,不知道如何激活,在哪里输 ...
- Python中生成器,迭代器,以及一些常用的内置函数.
知识点总结 生成器 生成器的本质就是迭代器. 迭代器:Python中提供的已经写好的工具或者通过数据转化得来的. 生成器:需要我们自己用Python代码构建的 创建生成器的三种方法: 通过生成器函数 ...
- python编写简单的html登陆页面(4)
python编写简单的html登陆页面(4) 1 在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将动态态分配数据,建立表格,存放学生信息 2 实现的效果如下: 3 动 ...
- JS 九九运算表
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- USACO 2008 Nov Gold 3.Light Switching 线段树
Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...
- Day 08 字符编码
字符编码 计算机基础 启动应用程序 1.双击QQ 2.操作系统接受指定然后把该操作转化为0和1发送给CPU 3.CPU接受指令然后把指令发给内存 4.内存接受指令把指令发送给硬盘获取数据 5.QQ在内 ...
- Python数据分析3------数据预处理
一.数据清洗 这一个步骤可以和数据探索并行. (1)标签分类数据处理:LabelEncoder[将分类数据变成0-n的值] from sklearn.prepocessing import Label ...
- 训练1-X
输入n(n<100)个数,找出其中最小的数,将它与最前面的数交换后输出这些数. Input 输入数据有多组,每组占一行,每行的开始是一个整数n,表示这个测试实例的数值的个数,跟着就是n个整数.n ...
- Jenkins学习总结(6)——了解DevOps的前世今生
DevOps是什么?从哪里来? DevOps的概念 DevOps一词的来自于Development和Operations的组合,突出重视软件开发人员和运维人员的沟通合作,通过自动化流程来使得软件构建. ...
- applicationContext-solr.xml
一.动态切换单机和集群 spring-solr 的配置 <!-- 单机版 solrj --> <bean id = "httpSolrServer" class= ...