zoukankan      html  css  js  c++  java
  • 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 }

  • 相关阅读:
    Codesys——限定符的使用方法[来自Codesys的Help]
    分页后台
    多条件查询判断
    添加跟反射
    试图页面分页首选
    动态游标存储过程 表名为参数
    索引器
    泛型 Generics
    Win10 锁屏图片 路径
    SQL2014 error 40 ( Microsoft SQL Server, 错误2)
  • 原文地址:https://www.cnblogs.com/yxh-amysear/p/8422643.html
Copyright © 2011-2022 走看看