时间限制: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

来源:
2008年北京大学图形实验室计算机研究生机试真题

思路:

大数运算类题目,用字符串或数组来做。

代码:

#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(整数相加) (大数运算)的更多相关文章

  1. 九度OJ 1137:浮点数加法 (大数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2725 解决:736 题目描述: 求2个浮点数相加的和 题目中输入输出中出现浮点数都有如下的形式: P1P2...Pi.Q1Q2...Qj ...

  2. 九度OJ 1129:Skew数 (大数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:734 解决:548 题目描述: 在 skew binary表示中, 第 k 位的值xk表示xk*(2k+1-1).  每个位上的可能数字是0 ...

  3. 九度OJ 1198:a+b (大数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6745 解决:2320 题目描述: 实现一个加法器,使其能够输出a+b的值. 输入: 输入包括两个数a和b,其中a和b的位数不超过1000位 ...

  4. 九度OJ 1514 数值的整数次方【算法】

    题目地址:http://ac.jobdu.com/problem.php?pid=1514 题目描述: 给定一个double类型的浮点数base和int类型的整数exponent.求base的expo ...

  5. 九度OJ 1190:大整数排序 (大数运算、排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3219 解决:1467 题目描述: 对N个长度最长可达到1000的数进行排序. 输入: 输入第一行为一个整数N,(1<=N<=1 ...

  6. 九度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总共有六种不 ...

  7. 九度oj 题目1373:整数中1出现的次数(从1到n整数中1出现的次数)

    题目描述: 亲们!!我们的外国友人YZ这几天总是睡不好,初中奥数里有一个题目一直困扰着他,特此他向JOBDU发来求助信,希望亲们能帮帮他.问题是:求出1~13的整数中1出现的次数,并算出100~130 ...

  8. 九度OJ 1125:大整数的因子 (大数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:974 解决:494 题目描述: 已知正整数k满足2<=k<=9,现给出长度最大为30位的十进制非负整数c,求所有能整除c的k. ...

  9. 九度oj 题目1063:整数和

    题目1063:整数和 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4043 解决:2638 题目描述: 编写程序,读入一个整数N.若N为非负数,则计算N到2N之间的整数和:若N为一个负数 ...

随机推荐

  1. C#:使用WebRequest类请求数据

    本文翻译于:https://msdn.microsoft.com/en-us/library/456dfw4f(v=vs.110).aspx 下列程序描述的步骤用于从服务器请求一个资源,例如,一个We ...

  2. vue.js源码学习分享(一)

    今天看了vue.js源码  发现非常不错,想一边看一遍写博客和大家分享 /** * Convert a value to a string that is actually rendered. *转换 ...

  3. Install Battery Historian

    1. Recommended extra packages for Trusty 14.04 $ sudo apt-get update $ sudo apt-get install \ linux- ...

  4. iOS开发之手势gesture详解(二)

    与其他用户界面控件交互 UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用 ...

  5. Ubuntu 16.04下安装WineHQ

    说明: 1.Wine和WIneHQ没什么区别,新版和旧版的问题. 2.安装了深度的Wine包也可以和WineHQ一起兼容,因为深度的应用名已经加了deepin前缀,所以不冲突. 3.安装了Wine之后 ...

  6. 迅雷中Peer连接信息中的状态解释(转)

    在标准 Peer-to-Peer(P2P 点对点网络)中,以"Flags"表示 Peer Status(Peer 状态).其中: D - 正从 Peer 下载(感兴趣:解阻塞)搜索 ...

  7. Oracle hidden costs revealed, Part2 – Using DTrace to find why writes in SYSTEM tablespace are slower than in others

    http://blog.tanelpoder.com/2008/09/02/oracle-hidden-costs-revealed-part2-using-dtrace-to-find-why-wr ...

  8. EventBus3.0使用笔记.md

    事件总线这个其实没什么好说的,除了已经ondestroy的fragment或者activity不能接受外,只要定义了的都能接收消息 代码如下,需要注意的一点就是接收的监听事件必须用public修饰并且 ...

  9. 非GUI模式下运行JMeter和远程启动JMeter

    JMeter是一款非常不错的免费开源压力测试工具,越来越多的公司在使用.不过,在使用过程中可能会存在一些问题,比如:GUI模式非常消耗资源,单个客户端测试无法达到目标压力.而使用非 GUI 模式,即命 ...

  10. 如何将MID音乐转换成MP3

    1 使用Direct MIDI to MP3 Converter这个软件,你可以从下面这个网站下载:http://www.hanzify.org/index.php?Go=Show::List& ...