• HDU 1047 Integer Inquiry


    Integer Inquiry

    http://acm.hdu.edu.cn/showproblem.php?pid=1047

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7564    Accepted Submission(s): 1961

    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
     
    Source
     
     
    用string练习
     
    #include<iostream>
    #include<cstring>
    
    using namespace std;
    
    string add(string str1,string str2){
        int len1=str1.length();
        int len2=str2.length();
        int i;
        if(len1<len2){
            for(i=1;i<=len2-len1;i++)
                str1="0"+str1;
        }else{
            for(i=1;i<=len1-len2;i++)
                str2="0"+str2;
        }
        len1=str1.length();
        int pre=0,tmp=0;
        string str;
        for(i=len1-1;i>=0;i--){
            tmp=str1[i]-'0'+str2[i]-'0'+pre;
            pre=tmp/10;
            tmp%=10;
            str=char(tmp+'0')+str;
        }
        if(pre!=0)
            str=char(pre+'0')+str;
        return str;
    }
    
    int main(){
        int t;
        cin>>t;
        while(t--){
            string sum="0",str;
            while(cin>>str){
                if(str=="0")
                    break;
                sum=add(sum,str);
            }
            cout<<sum<<endl;
            if(t!=0)
                cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    七牛云上传文件
    微博三方登录
    异步任务 --- django-celery
    阿里云短信服务
    Redis五大数据结构和使用方法
    千万不要买我们家的鞋子!
    Firebug控制台详解
    【转】android 按home键返回到桌面后,再按桌面应用图标又重新打开该应用的解决方法
    【转】android中webview使用的一些细节
    JSONException: Value of type java.lang.String cannot be converted to JSONObject
  • 原文地址:https://www.cnblogs.com/jackge/p/2834613.html
Copyright © 2020-2023  润新知