九度OJ 1119:Integer Inquiry(整数相加) (大数运算)
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:679
解决:357
- 题目描述:
-
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.)
- 输入:
-
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.
- 输出:
-
Your program should output the sum of the VeryLongIntegers given in the input.
- 样例输入:
-
123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
- 样例输出:
-
370370367037037036703703703670
- 提示:
-
注意输入数据中,VeryLongInteger 可能有前导0
思路:
大数运算类题目,用字符串或数组来做。
代码:
#include <stdio.h>
#include <string.h>
#define M 105
void print(int *a)
{
int i, j;
for (i=0; i<M; i++)
{
if (a[i] != 0)
break;
}
if (i == M)
printf("0\n");
else
{
for (j=i; j<M; j++)
printf("%d", a[j]);
printf("\n");
}
}
int main(void)
{
int n, i, j;
int a[M], b[M];
char s[M];
memset(a, 0, M*sizeof(int));
while (scanf("%s", s) != EOF)
{
if (strcmp(s, "0") == 0)
break;
memset(b, 0, M*sizeof(int));
n = strlen(s);
j = M-n;
for (i=0; i<n; i++)
b[j++] = s[i]-'0';
for (i=M-1; i>0; i--)
{
a[i] += b[i];
if (a[i] >= 10)
{
a[i-1] ++;
a[i] -= 10;
}
}
}
print(a);
return 0;
}
/**************************************************************
Problem: 1119
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/
九度OJ 1119:Integer Inquiry(整数相加) (大数运算)的更多相关文章
- 九度OJ 1137:浮点数加法 (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2725 解决:736 题目描述: 求2个浮点数相加的和 题目中输入输出中出现浮点数都有如下的形式: P1P2...Pi.Q1Q2...Qj ...
- 九度OJ 1129:Skew数 (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:734 解决:548 题目描述: 在 skew binary表示中, 第 k 位的值xk表示xk*(2k+1-1). 每个位上的可能数字是0 ...
- 九度OJ 1198:a+b (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6745 解决:2320 题目描述: 实现一个加法器,使其能够输出a+b的值. 输入: 输入包括两个数a和b,其中a和b的位数不超过1000位 ...
- 九度OJ 1514 数值的整数次方【算法】
题目地址:http://ac.jobdu.com/problem.php?pid=1514 题目描述: 给定一个double类型的浮点数base和int类型的整数exponent.求base的expo ...
- 九度OJ 1190:大整数排序 (大数运算、排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3219 解决:1467 题目描述: 对N个长度最长可达到1000的数进行排序. 输入: 输入第一行为一个整数N,(1<=N<=1 ...
- 九度oj 题目1084:整数拆分 清华大学2010年机试题目
题目描述: 一个整数总可以拆分为2的幂的和,例如:7=1+2+4 7=1+2+2+2 7=1+1+1+4 7=1+1+1+2+2 7=1+1+1+1+1+2 7=1+1+1+1+1+1+1总共有六种不 ...
- 九度oj 题目1373:整数中1出现的次数(从1到n整数中1出现的次数)
题目描述: 亲们!!我们的外国友人YZ这几天总是睡不好,初中奥数里有一个题目一直困扰着他,特此他向JOBDU发来求助信,希望亲们能帮帮他.问题是:求出1~13的整数中1出现的次数,并算出100~130 ...
- 九度OJ 1125:大整数的因子 (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:974 解决:494 题目描述: 已知正整数k满足2<=k<=9,现给出长度最大为30位的十进制非负整数c,求所有能整除c的k. ...
- 九度oj 题目1063:整数和
题目1063:整数和 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4043 解决:2638 题目描述: 编写程序,读入一个整数N.若N为非负数,则计算N到2N之间的整数和:若N为一个负数 ...
随机推荐
- 【kindeditor】kindeditor的使用
官网:http://kindeditor.net/demo.php 效果:
- yii批量插入数据
现在有如下数据: 查看代码 打印 1 $user=array( 2 0=>array('id'=>1,'name'=>'张三'), 3 0=>array(' ...
- 首次远程安装 GlassFish 后以远程 Web 方式访问其后台管理系统出现错误的解决方法(修订)
首次远程安装 GlassFish 服务后,如果以远程 Web 方式访问其后台管理系统,会提示 Secure Admin must be enabled to access the DAS remote ...
- consul UI用127可以访问,指定ip无法访问
./consul agent -dev 只能127.0.0.1可以访问 ./consul agent -dev -client 0.0.0.0 -ui 指定ip可以访问
- AC日记——最小路径覆盖问题 洛谷 P2764
题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...
- Anaconda3中Python3.5和Python2.7共存
开始-所有程序-Anaconda3-Anaconda Prompt conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/a ...
- 洛谷—— P1503 鬼子进村
https://www.luogu.org/problemnew/show/P1503 题目背景 小卡正在新家的客厅中看电视.电视里正在播放放了千八百次依旧重播的<亮剑>,剧中李云龙带领的 ...
- Linux字符模式下如何设置/删除环境变量
Linux字符模式下设置/删除环境变量方法: bash下 设置:export 变量名=变量值 删除:unset 变量名 csh下 设置:setenv 变量名 变量值 删除:unsetenv 变量名 h ...
- BZOJ题目(持续更新)
bzoj1009:kmp想法+递推+矩阵快速幂.很好的想法,考虑用长串去kmp匹配短串,dp[i][j]表示匹配指针分别指在i.j位置时候,前i位母字符串一共有多少种可能性,那么dp[i][j]=Σd ...
- 纯CSS3美化radio和checkbox
如题,主要通过CSS3来实现将radio和checkbox美化的效果.可是兼容性并非非常好,PC端仅仅支持chrome浏览器(IE和Firefox測试不行,其它没有很多其它測试).然后微信端和QQ端訪 ...