POJ 1503 && HDU 1047 Integer Inquiry(高精度)
来源:互联网 发布:淘宝号查询信誉网址 编辑:程序博客网 时间:2024/06/06 07:14
Description
大整数加法,每个整数至多包含100个数字,最多100个整数相加,计算并输出结果
Input
最多输入100行数据,每行输入一个正整数,输入0结束输入
Output
输出所有正整数累加的结果
Sample Input
123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
Sample Output
370370367037037036703703703670
Solution
简单模拟
用数组存正整数,从低位往高位存,加的时候注意进位
Code
#include<stdio.h>#include<string.h>#define maxn 105int main(){ int map[maxn][maxn]; memset(map,0,sizeof(map));//初始化 char s[maxn]; int k=0; while(gets(s)&&strcmp(s,"0")!=0)//以字符串形式读入整数 { int len=strlen(s); for(int i=len-1;i>=0;i--)//将字符串转化为整型数组存储 map[k][len-i-1]=s[i]-'0'; k++;//记录正整数数量 } int temp=0,ans[maxn];//temp为每次进位值,ans存储最终答案 for(int i=0;i<maxn;i++) { int res=0; for(int j=0;j<k;j++) res+=map[j][i]; ans[i]=(res+temp)%10;//记录答案 temp=(res+temp)/10;//记录进位值 } int i=maxn-1; while(ans[i]==0)//判断答案位数 i--; for(;i>=0;i--) printf("%d",ans[i]); printf("\n"); return 0;}
0 0
- POJ 1503 && HDU 1047 Integer Inquiry(高精度)
- POJ 1503 Integer Inquiry(高精度)
- HDU 1047 Integer Inquiry(高精度加法)
- hdu 1047 Integer Inquiry(高精度加法)
- JAVA hdu 1047 Integer Inquiry(高精度)
- HDU - 1047 - Integer Inquiry (大数高精度)
- poj 1503 Integer Inquiry高精度
- poj 1503 Integer Inquiry【高精度】
- POJ 1503 Integer Inquiry 高精度
- POJ 1503 Integer Inquiry(高精度运算)
- POJ 1503 Integer Inquiry 高精度加法
- poj 1503Integer Inquiry(高精度 水题)
- POJ 1503 Integer Inquiry 高精度加法
- hdu 1047 Integer Inquiry(高精度数)
- Integer Inquiry(高精度)
- (高精度运算4.7.23)POJ 1503 Integer Inquiry(大数累加)
- POJ – 1503 Integer Inquiry Integer Inquiry
- POJ 1503 Integer Inquiry
- 进程管理与SELinux初探
- 《Artech的WCF之旅系列》系列技术文章整理收藏
- 仿QQ软件收获
- 关于版本管理的一些初步理解
- 进程与PCB的关系如何看???
- POJ 1503 && HDU 1047 Integer Inquiry(高精度)
- AngularJS从构建项目开始
- tar命令的详细解释
- hdoj1078_FatMouse and Cheese(dp)
- android用pull解析xml文件
- POJ 1504 Adding Reversed Numbers(水~)
- STM32 SPI总线移植fatfs产生硬件异常问题
- Mac下Charles手机抓包与截包篡改报文
- 安卓学习笔记之通知栏的使用