美文网首页
acm训练19,1,20 uva424,高精度算法

acm训练19,1,20 uva424,高精度算法

作者: xcpooo | 来源:发表于2019-01-23 03:12 被阅读0次

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.)
Input
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.
Output
Your program should output the sum of the VeryLongIntegers given in the input.
Sample Input
123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
Sample Output
370370367037037036703703703670

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>

using namespace std;///

#define MAX_BIT 100

void toDigit(char *str, int *digit)//把char转为int数组,倒序方便输出
{
    int len = strlen(str);
    for (int i = 0, j = len - 1; i < len; i++, j--) {
        digit[i] = (int)(str[j] - '0');
    }
}

void  add(int *digitNum,int *rslt) //相加函数,rslt为结果
{
    int s = 0;
    for (int i = 0; i < MAX_BIT; i++) {
        s = rslt[i] + digitNum[i] + s;
        rslt[i] = s % 10;
        s = s / 10;
    }

}




int main()
{
    char strNum[MAX_BIT];
    int rslt[MAX_BIT], digitNum[MAX_BIT];
    memset(rslt, 0, sizeof(rslt));
    while (scanf("%s", strNum) && strNum[0] != '0') {
        // init
        memset(digitNum, 0, sizeof(digitNum));

        toDigit(strNum, digitNum);


        int s = 0;
        for (int i = 0; i < MAX_BIT; i++) {
            s = rslt[i] + digitNum[i] + s;
            rslt[i] = s % 10;
            s = s / 10;
        }
    }

    int i = MAX_BIT;
    while (rslt[--i] == 0);
    while (i >= 0) {
        printf("%d", rslt[i--]);
    }
    printf("\n");

    return 0;
}

相关文章

  • acm训练19,1,20 uva424,高精度算法

    One of the first users of BIT’s new supercomputer was Chi...

  • ACM算法

    树状数组 https://blog.csdn.net/Small_Orange_glory/article/det...

  • 贪心算法 & 动态规划基础题

    [TOC] acm 标签(空格分隔): acm 贪心算法 51Nod 1191消灭兔子 越好,故对兔子血量升序排列...

  • 高精度算法

    高精度计算主要思想是:把巨大无比无法直接计算的数以字符串的形式读入转化成数字按位存入数组(倒着存入)依照竖式计算的...

  • 高精度算法

    四种类型高精度算法[仅对C++而言] 1.A+B:两个大整数(A和B的位数为10^6)相加 a.利用数组存储大整数...

  • 常用算法代码.pdf

    【下载地址】 ACM/ICPC 算法代码库,供日常使用参考。 目录 ..........................

  • SUST ACM Summer Training(1)

    SUST ACM Summer Training(陕西科技大学 暑期ACM训练) 10道结构体和排序类型问题 题解...

  • 论文杀器LaTeX用法汇总(3)——实战·ACM代码模板

    这次让我们来做一个LaTeX的实例——ACM代码模板。ACM/ICPC是全球顶尖的算法赛事,比赛时选手可以自带纸质...

  • 大一上acm总结

    先说说都学了些什么吧。1 . 三个算法专题,高精度,dfs,bfs,高精度基础应用没什么问题,dfs,bfs,题做...

  • HDU2063

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 匈牙利算法...

网友评论

      本文标题:acm训练19,1,20 uva424,高精度算法

      本文链接:https://www.haomeiwen.com/subject/zfvdjqtx.html