Integer Inquiry(UVA—424)

简介: Integer Inquiry(UVA—424)

题目:

One of the first users of BIT’s new supercomputer was Chip Diller. He extended his exploration ofpowers 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 Skyapartments on Third Street.)

Input

The input will consist of at most 100 lines of text, each of which contains a single VeryLongInte-ger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (noVeryLongInteger 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

<font color=red Sample Output

370370367037037036703703703670

解题思路:这个题是高精度的问题,多个大数相加的结果.

程序代码:

#include<stdio.h>
#include<string.h>
int a[50000],b[50000],c[55000];
char s[200];
int main()
{
  int n,m,i,j,k;
  memset(a,0,sizeof(a));
  scanf("%s",s);
  m=strlen(s);
  j=0;
  for(i=m-1;i>=0;i--)
    a[j++]=s[i]-'0';
  while(scanf("%s",s)!=EOF)
  {
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    if(s[0]=='0')
      break;
    n=strlen(s);
    j=0;
    for(i=n-1;i>=0;i--)
      b[j++]=s[i]-'0';
    if(n>m)
      k=n;
    else
      k=m;
    for(i=0;i<k;i++)
    {
      c[i]=a[i]+b[i]+c[i];
      if(c[i]>=10)
      {
        c[i+1]++;
        c[i]=c[i]%10;
      }
    }
    if(c[k]!=0)
      k++;
    for(i=0;i<k;i++)
      a[i]=c[i];
    m=k;  
  }
  for(i=m-1;i>=0;i--)
    printf("%d",a[i]);
  printf("\n");
  return 0; 
}













相关文章
|
Kubernetes Serverless 调度
异步任务处理系统问题之在阿里云函数计算平台上用户提交异步任务的问题如何解决
异步任务处理系统问题之在阿里云函数计算平台上用户提交异步任务的问题如何解决
140 0
|
存储 语音技术 Python
语音识别,函数综合案例,黑马ATM,/t/t一个对不齐,用两个/t,数据容器入门,数据容器可以分为列表(list)、元组(tuple)、字符串(str)、集合(set)、字典(dict)
语音识别,函数综合案例,黑马ATM,/t/t一个对不齐,用两个/t,数据容器入门,数据容器可以分为列表(list)、元组(tuple)、字符串(str)、集合(set)、字典(dict)
|
存储 前端开发
什么是 CSS
什么是 CSS。
138 6
|
算法 测试技术 C#
C++字典树算法:找出强数对的最大异或值 II
C++字典树算法:找出强数对的最大异或值 II
|
IDE Linux 开发工具
Linux [工具]
Linux [工具]
|
算法 Linux
17.3 Linux libmcrypt安装
libmcrypt 是加密算法扩展库,支持 DES、3DES、RIJNDAEL、Twofish、IDEA、GOST、CAST-256、ARCFOUR、SERPENT、SAFER+ 等算法。安装步骤如下。
588 0
17.3 Linux libmcrypt安装
|
前端开发 数据可视化 JavaScript
漏刻有时数据可视化大屏核心框架模版更换前端模版操作(2)API开发及数据调用
漏刻有时数据可视化大屏核心框架模版更换前端模版操作(2)API开发及数据调用
183 0
|
安全
阿里云无影云桌面续费别忘了续费带宽
阿里云无影云桌面续费别忘了安全办公网(固定带宽)续费
744 0
阿里云无影云桌面续费别忘了续费带宽
|
关系型数据库 MySQL
MySQL里Wating for Slave workers to free pending events到底在等什么
MySQL里Wating for Slave workers to free pending events到底在等什么
156 0
|
数据采集 存储 安全
这些知识点你都了解了吗?#CISSP-D2:资产安全
资产安全知识域涵盖信息和信息资产在其生命周期中的安全保护,包括恰当的收集、分类、处置以及控制措施的选择和使用。本知识域的重要概念包括数据的所有权、隐私、数据安全控制和相关密码学的应用。安全和风险管理知识域包含了许多基本的信息安全概念、原则以及信息安全管理相关活动和方法。
739 0
这些知识点你都了解了吗?#CISSP-D2:资产安全