zoukankan      html  css  js  c++  java
  • HDU 1047 Integer Inquiry


     

                   Integer Inquiry



     

    Problem 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.


    This problem contains multiple test cases!

    The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

    The output format consists of N output blocks. There is a blank line between output blocks.
     

     

    Sample Input
    1
    123456789012345678901234567890
    123456789012345678901234567890
    123456789012345678901234567890
    0
     

     

    Sample Output
    370370367037037036703703703670
     
    简单的大数累加.
     
    代码:
     1 #include<cstdio>
     2 #include<cstring>
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     //freopen("in.txt","r",stdin);
     8     char s[105];
     9     int a[1005],b[1005];
    10     int t,j,i;
    11     scanf("%d",&t);
    12     while(t--)
    13     {
    14         memset(a,0,sizeof(a));
    15         while(scanf("%s",s)&&strcmp(s,"0")!=0)
    16         {
    17             memset(b,0,sizeof(b));
    18             int len=strlen(s);
    19             for(j=0,i=len-1;i>=0;i--)
    20             b[j++]=s[i]-'0';
    21             for(i=0;i<1005;i++)
    22             {
    23                 a[i]+=b[i];
    24                 if(a[i]>=10)
    25                 {
    26                     a[i]-=10;
    27                     a[i+1]+=1;
    28                 }
    29             }
    30         }
    31         for(i=1004;i>=0;i--)
    32         if(a[i])break;
    33         if(i==-1)
    34         printf("0");
    35         for(;i>=0;i--)
    36         printf("%d",a[i]);
    37         printf("
    ");
    38         if(t!=0)
    39         printf("
    ");
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    [PKUWC2018][LOJ2537]Minimax(线段树合并)
    [NOI2019][洛谷P5471]弹跳(dijkstra+KD-Tree)
    [BZOJ4770]图样(概率期望、二进制数位dp)
    [SPOJ11482][BZOJ2787]Count on a trie(广义SA+长链剖分+BIT)
    [HEOI/TJOI2016][洛谷P4094]字符串(SA+主席树)
    [BZOJ3270]博物馆(矩阵求逆)
    [NOI2016][洛谷P1117]优秀的拆分(SA)
    [NOI2018][洛谷P4770]你的名字(SAM+SA+主席树)
    设置echarts两个y轴的0点一致
    echarts中饼图或环形图的高亮效果(点击高亮/默认某一条高亮)
  • 原文地址:https://www.cnblogs.com/homura/p/4674190.html
Copyright © 2011-2022 走看看