• POJ 1503 -- Integer Inquiry


     Integer Inquiry

    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 35353   Accepted: 13781

    Description

    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

    Source

     

     几个大数相加= = 

     1 #include<iostream>
     2 #include<cstring>
     3 using namespace std;
     4 char a[101],BigInt[103];
     5 int main()
     6 {
     7     memset(BigInt,0,sizeof(BigInt));
     8     int L=0;
     9     while(true)
    10     {
    11         memset(a,0,sizeof(a));
    12         cin>>a;
    13         if(strcmp(a,"0")==0)
    14        {
    15            for(int j=L-1;j>=0;j--)
    16            {
    17                cout<<int(BigInt[j]);
    18            }
    19            cout<<endl;
    20            break;
    21        }
    22         int aLen = strlen(a);
    23         int BigJ = 0;
    24         for(int j=aLen-1;j>=0;j--)
    25         {
    26             BigInt[BigJ++] += a[j]-'0';
    27         }
    28         L  = L>aLen?L:aLen;//记录当前和的位数
    29         int k;
    30         for(k = 0;k<L;k++)
    31         {
    32             if(BigInt[k]>=10)
    33             {
    34                 BigInt[k] -= 10;
    35                 BigInt[k+1] += 1;
    36             }
    37         }
    38         if(BigInt[k]) L++;
    39 
    40     }
    41 
    42     return 0;
    43 }

  • 相关阅读:
    Vscode开发工具中的Simple React Snippets插件,对React开发有哪些便捷
    函数防抖和节流
    4.怎么样用CSS实现一个loading效果
    3.常见清除浮动的
    2.css处理各种溢出
    1. css画三角形
    2.javascript中call()和apply()区别
    1.js的继承的实现方法
    css、js小技巧
    JS函数声明和函数表达式的关系
  • 原文地址:https://www.cnblogs.com/yxh-amysear/p/8422643.html
Copyright © 2020-2023  润新知