时间限制: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. batch.bat explaination

    1.Echo 命令 打开回显或关闭请求回显功能,或显示消息.如果没有任何参数,echo 命令将显示当前回显设置. 语法 echo [{on|off}] [message] Sample篅echo of ...

  2. ajax请求Url加参数的使用方法

    var cId = $(this).data('claim-id');var adoptUrl = "<?php echo $this->createUrl('claim/app ...

  3. 完美解决xhost +报错: unable to open display ""

    https://blog.csdn.net/wojiuguowei/article/details/79201845

  4. 记一次安装centos7及gnome桌面

    https://blog.csdn.net/bingbingtea/article/details/79553669

  5. Codeforces 868F Yet Another Minimization Problem(分治+莫队优化DP)

    题目链接  Yet Another Minimization Problem 题意  给定一个序列,现在要把这个序列分成k个连续的连续子序列.求每个连续子序列价值和的最小值. 设$f[i][j]$为前 ...

  6. CentOS配置sshd

    用SSH来远程管理计算机,就不用到计算机实际地点来回跑了 环境:服务器:CentOS6.6,客户机win8.1 putty 配置服务器: 1.检查SSHD是否安装(默认情况下是系统自带的),使用命令 ...

  7. 一次完整的http请求过程以及网络I/O模型select、epoll

    a.一次完整的http请求过程 1.域名解析,得到域名对应的IP; 2.三次握手,客户端与服务器通过socket建立TCP/IP连接; 3.浏览器向服务器发送http请求,如:GET/index.ht ...

  8. NMM3DViewer 设计

    在FrameworkInterfaces工程的INMM3DServer.cs中定义了 岩石材料结构 BlockMaterial  -----> StrBLOCKProperty     publ ...

  9. class文件无论是32位还是64位jdk编译出来的,都可以通用

    class文件无论是32位还是64位jdk编译出来的,都可以通用 学习了:https://blog.csdn.net/z3111001358/article/details/53364066 java ...

  10. 验证loadrunner对Ajax内容的校验

    前一阵和开发的同事一起測试某个系统的性能.此系统是发送Ajax请求到后台,再调用第三方的某项服务. 第三方服务的性能由不得我们控制.因此开发者做了一下改进.超时则直接返回. 于是在loadrunner ...