zoukankan      html  css  js  c++  java
  • [解题报告]424 Integer Inquiry

     Integer Inquiry 

    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



    现在大数题基本上习惯用字符组处理了
    #include<stdio.h>
    #include<string.h>
    char p[1000];
    int o[1001];
    int main()
    {
     int a,b,c,i;
     while(scanf("%s",p)!=EOF)//输入加数,以字符组形式存储
     {
      if(p[0]=='0')break;
      b=strlen(p);
      for(a=b-1,i=0;a>=0;a--,i++)
       o[i]+=p[a]-'0';//将输入的加数倒序存储为数组,加数每位占一个单位。由于输入是从左到右,而运算是从右到左,这样处理符合从右到左的运算习惯
     }
     for(b=0;b<=150;b++)
     {
      if(o[b]>=10)//如果输入的数大于是10,则保留个位,向后一位加上自己的十位数部分,也就是进位
      {
       o[b+1]+=o[b]/10;
       o[b]=o[b]%10;
      }
     }
     c=0;
     for(b=150;b>=0;b--)//输出还是要从左到右输出,所以倒序输出
     {
      if(o[b]!= 0)//只输出非零部分
       c=1;
      if(c)
       printf("%d",o[b]);
     }
    if(c==0)//这是针对输入为0的情况。也就是第10行语句退出循环后执行的部分
    printf("0");
     printf("\n");
     return 0;
    }
  • 相关阅读:
    Nginx配置简单说明
    JVM需要知道的一些设置参数
    Maven仓库(私服)中上传第三方jar包
    maven本地资源库设置
    sweetalert2使用教程
    《算法导论》学习笔记——二叉搜索树
    散列表
    跨域请求
    mvn常用命令
    Springmvc配置笔记
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2924685.html
Copyright © 2011-2022 走看看