zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Eclipse的tab键为4个空格完整方法 附:阿里代码开发规范书
    Linux系统 安装JDK和tomcat
    Window10安装linux
    oracle 查询表重复数据 并 删除保留一条
    Oracle 新增数据 insert into整理
    业需软需word小技巧
    oracle数据库创建表且主键自增
    eclipse更改jdk版本(1.6》1.7 以此类推)
    pytest框架优化——清理历史截图图片和allure报告文件
    allure定制化输出测试报告,让报告锦上添花!
  • 原文地址:https://www.cnblogs.com/jackge/p/2834613.html
Copyright © 2011-2022 走看看