Integer Inquiry
来源:互联网 发布:网络机顶盒电视猫 编辑:程序博客网 时间:2024/05/21 10:48
Integer Inquiry
One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)
Input
The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
The final input line will contain a single zero on a line by itself.
Output
Your program should output the sum of the VeryLongIntegers given in the input.
Sample Input
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900
Sample Output
370370367037037036703703703670
高精度加法,找到一个大神的模版,觉得很好用。#include<iostream>#include<cstdio>#include<cstring>using namespace std;string highadd(string str1, string str2){ string str; int len1 = str1.length(); int len2 = str2.length(); if(len1 < len2){ for(int i=1; i<=len2-len1; i++) str1 = "0" + str1; } else if(len1 > len2){ for(int i=1; i<=len1-len2; i++) str2 = "0" + str2; } len1 = str1.length(); int next=0; int temp; for (int i=len1-1; i>=0; i--) { temp = str1[i]-'0' + str2[i]-'0' +next; next=temp/10; temp%=10; str=char(temp+'0')+str; } if(next!=0) str = char(next+'0')+str; return str;}int main(){ string sum = "0"; string str1; while(cin>>str1) { if(str1 == "0") { break; } sum = highadd(sum, str1); } cout<<sum<<endl;}
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- Integer Inquiry
- POJ – 1503 Integer Inquiry Integer Inquiry
- 1503 Integer Inquiry
- HDU1047 Integer Inquiry
- java常见错误整理
- 使用 Jrebel 插件实现热加载
- CSS目前最新版本为CSS3,是能够真正做到网页表现与内容分离的一种样式设计语言
- navigationBar 标题字体颜色设置
- libnet进行编程时,libnet_init()无法找到网卡的解决方法。
- Integer Inquiry
- java设计模式初体验之观察者模式
- OpenGL ES基本概念介绍
- android pcm编解码
- 在DAO中如何获得session对象
- sed的使用举例 --Unix Shell
- win7系统使用种种
- u-boot-2009.08在mini2440上的移植
- UILocalNotification 本地通知的应用实例