zoukankan      html  css  js  c++  java
  • Problem D: Integer Inquiry

    Problem D: Integer Inquiry
    Time Limit: 1 Sec Memory Limit: 128 MB
    Submit: 41 Solved: 12
    [Submit][Status][Web Board]
    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
    my answer:

    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    #include<string>
    using namespace std;
    int main()
    {
        char a[101];
        char b[101];
        memset(a,'0',sizeof(a));
        memset(b,'0',sizeof(b));
     
        while(cin>>b)
        {
            int sum[101]={0};
            int t2=strlen(b),p=t2;
            b[t2]='0';
            for(int i=100;t2-1>=0;i--,t2--){
                    b[i]=b[t2-1];
                    b[t2-1]='0';
                }
            while(scanf("%s",a)&&strcmp(a,"0"))
            {
                int t1=strlen(a),q=t1;
                a[t1]='0';
                for(int i=100;t1-1>=0;i--,t1--){
                    a[i]=a[t1-1];
                    a[t1-1]='0';
                }
                for(int j=100;j>=0;j--)
                    b[j]=(b[j]-'0')+(a[j]-'0')+'0';
                for(int i=100;i>=0;i--)
                    sum[i]=b[i]-'0';
     
                for(int j=100;j>=0;j--){
                    sum[j-1]+=sum[j]/10;
                    sum[j]=sum[j]%10;
                }
            }
            memset(a,'0',sizeof(a));
            memset(b,'0',sizeof(b));
            int start=0;
            for(int k=0;k<=100;k++)
                if(sum[k]==0)
                    start++;
                else
                    break;
            for(int k=start;k<=100;k++)
                cout<<sum[k];
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    SQL Server Audit监控触发器状态
    SQL Server 数据变更时间戳(timestamp)在复制中的运用
    SQL Server 更改跟踪(Chang Tracking)监控表数据
    SQL Server 变更数据捕获(CDC)监控表数据
    SQL Server 事件通知(Event notifications)
    SQL Server 堆表行存储大小(Record Size)
    SQL Server DDL触发器运用
    SQL Server 默认跟踪(Default Trace)
    SQL Server 创建数据库邮件
    SQL Server 跨网段(跨机房)FTP复制
  • 原文地址:https://www.cnblogs.com/NYNU-ACM/p/4236895.html
Copyright © 2011-2022 走看看