时间限制: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. CSS 盒模型、解决方案、BFC 原理讲解--摘抄

    PS:内容比较基础,目的只是覆盖面试知识点,大佬可以 history.back(-1) W3C 标准盒模型 & IE 怪异盒模型 页面上显示的每个元素(包括内联元素)都可以看作一个盒子,即盒模 ...

  2. poj 3308(二分图的点权最小覆盖)

    Paratroopers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8325   Accepted: 2502 Desc ...

  3. 洛谷—— P1561 [USACO12JAN]爬山Mountain Climbing

    https://daniu.luogu.org/problemnew/show/P1561 题目描述 Farmer John has discovered that his cows produce ...

  4. 平衡树与可持久化treap

    平衡树(二叉树) 线段树不支持插入or删除一个数于是平衡树产生了 常见平衡树:treap(比sbt慢,好写吧),SBT(快,比较好写,有些功能不支持),splay(特别慢,复杂度当做根号n来用,功能强 ...

  5. UVA - 10972 RevolC FaeLoN

    一道特别好的题qwq. 题目大意就是给你一个无向图,让你把边定向之后再加一些边使得这个图强连通,求最少需要加多少边. 一开始毫无头绪23333,数据范围让人摸不着头脑..... 然后开始画图,,,发现 ...

  6. 使用一个数组存储一个英文句子"java is an object oriented programing language"

    class fun { public static void main(String[] args) { String str="java is an object oriented pro ...

  7. PyTorch学习笔记之Tensors

    PyTorch Tensors are just like numpy arrays, but they can run on GPU.No built-in notion of computatio ...

  8. 好用的Python IDLE Sublime Text 3推荐

    Sublime Text 3 下载地址为 LINK, Sublime Text 3 is currently in beta. The latest build is 3114. 参考的激活方式为输入 ...

  9. xcode创建一个工程的多个taget,便于测试和发布多个版本

    背景:很多时候,我们需要在一个工程中创立多个target,也就是说我们希望同一份代码可以创建两个应用,放到模拟器或者真机上,或者是,我们平时有N多人合作开发,当测试的时候,在A这里装了一遍测A写的那块 ...

  10. 【CSS】使用CSS控制文字过多自动省略号

    使用CSS可以设置一下样式: <style> u,small{ overflow: hidden; text-overflow: ellipsis; display: -webkit-bo ...