时间限制: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. Z-Order(转)

    原文转自 http://www.th7.cn/system/win/201406/60715.shtml 窗口在子窗口链中的先后顺序也就是窗口在屏幕上显示时的前后顺序,在子窗口链里位置越靠前的窗口显示 ...

  2. 52深入理解C指针之---不透明指针

    该系列文章源于<深入理解C指针>的阅读与理解,由于本人的见识和知识的欠缺可能有误,还望大家批评指教.一.size_t:用于安全表示长度,所有平台和系统都会解析成自己对应的长度 1.定义:s ...

  3. PE+ 1.0 ( Pump Express Plus 1.0 )

    Dialog iW1788 for PE+ 1.0 Dialog iW1680 for PE PE+1.0 for up to 15W battery, improve charging time, ...

  4. LeetCode OJ——Longest Valid Parentheses

    http://oj.leetcode.com/problems/longest-valid-parentheses/ 最大括号匹配长度,括号是可以嵌套的 #include <string> ...

  5. AC日记——Propagating tree Codeforces 383c

    C. Propagating tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. [Bzoj4943][Noi2017]蚯蚓(hash)

    4943: [Noi2017]蚯蚓 Time Limit: 50 Sec  Memory Limit: 512 MBSubmit: 237  Solved: 110[Submit][Status][D ...

  7. es6系列-变量的解构赋值

    git地址: https://github.com/rainnaZR/es6-study/tree/master/src/destructuring 变量的解构赋值 变量的解构赋值: 数组, 对象, ...

  8. javascript 对象初探 (六)--- call()和apply()初探

    在javascript中,每个函数都具有call()和apply()两个方法,您可以用她们来触发函数,并指定相关的调用参数. 此外,这两个方法还有另一个功能,就是她可以让一个对象去‘借用‘另一个对象的 ...

  9. openfire Android学习(三)----会议室创建、加入以及查询会议室中所有成员等

    openfire 中的会议室不像QQ群一样,不能保存那些离线用户,加入会议室后,一旦断开连接,就会离开会议室. 虽然如此,但如果要实现也不是不可能,我们可以自己做后台来保存,有兴趣的可以去试着实现一下 ...

  10. win10安装scrapy

    前提已经安装好python2.7背景:scrapy框架,windows下的部署工作挺麻烦的.需要用的资源整合了一下可以为以后需要的同学节省不少时间. 相关文件:网盘链接: http://pan.bai ...