zoukankan      html  css  js  c++  java
  • POJ1503——字符串——Integer Inquiry

    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
    大意:高精度加法
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int sum[150];
    void add(char *a)
    {
      int len = strlen(a);
      int k = 1;
      for(int i = len - 1 ;i >= 0;i--){
            sum[k] += (a[i] - '0');
            sum[k+1] += sum[k]/10;
            sum[k] %= 10;
            k++;
      }
    }
     int main()
     {
         char a[105][105];
         for(int i = 0 ; ; i++){
            scanf("%s",a[i]);
            int n = strlen(a[i]);
            if(n == 1 && a[i][0] == '0')
                break;
            add(a[i]);
         }
        int flag = 0;
        for(int i = 110; i >= 1 ;i--){
          if(sum[i] == 0 && flag == 0)
            continue;
          else {
                flag = 1;
          printf("%d",sum[i]);
         }
        }
        return 0;
     }
    View Code
     
  • 相关阅读:
    ResNet主要思想(总结)
    TensorFlow2_200729系列---24、一些卷积网络创新点
    Android GIS开发系列-- 入门季(1) 起点
    [官方]Beyond Compare里面 二进制比较的含义.
    Chrome 下载地址
    本地图文直接复制到网页编辑器中
    本地图文直接复制到在线编辑器中
    js+php分片上传大文件源码
    js+php分片上传大文件插件
    js+php分片上传大文件控件
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4372688.html
Copyright © 2011-2022 走看看