HDOJ 1047

点击打开链接

//注意测试数据(其它就是有关大数的加法,由于这一题输入数据最大为100位,则不用考虑压缩)

Input
3

00
00
0

000
0

0

Output
0

0

0


代码:

//////////////////////////////////////////
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long int s[5005];
int n[110][5010];
int main()
{
    int t;
    int i,j,k;
    cin>>t;
    string str;
    while(t--){
        i=0;
        memset(s,0,sizeof(s));
        memset(n,0,sizeof(n));
        while(1){
            cin>>str;
            int len=str.size();
            if(str[0]=='0'&&len==1)
                break;
            for(j=len-1,k=0;j>=0;j--,k++){
                n[i][k]=str[j]-48;
            }
            i++;
         }

           for(k=0;k<=5000;k++){
               for(j=0;j<i;j++){
                  s[k]+=n[j][k];
               }
               if(s[k]>=10){
                  s[k+1]+=s[k]/10;
                  s[k]%=10;
               }
           }

        j=5000;
        while(j--){
            if(s[j]!=0)
                break;
        }
        if(j>=0){
         for(;j>=0;j--)
            printf("%d",s[j]);
         cout<<endl;
        }
        else
            cout<<0<<endl;
        if(t>=1)
            cout<<endl;
    }
    return 0;
}
时间: 2024-07-29 20:39:15

HDOJ 1047的相关文章

最大匹配-HDOJ 2458 Kindergarten

HDOJ 2458 Kindergarten Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids 

最大匹配-HDOJ 1068

HDOJ 1068 Girls and Boys . Problem Description the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study

C语言OJ项目参考(1047) 最大公约数和最小公倍数

1047: 求两个整数的最大公约数和最小公倍数 Description 写两个函数,分别求两个整数的最大公约数和最小公倍数,用主函数调用这两个函数,并输出结果两个整数由键盘输入. Input 两个数 Output 最大公约数 最小公倍数 Sample Input 6 15 Sample Output 3 30 HINT 主函数已给定如下,提交时不需要包含下述主函数 /* C代码 */ int main() { int n,m,gys,gbs; int gcd(int a, int b); int

hdoj 1007 两点之间最短距离的二分之一 提交之后超时了 求c语言解法 感激不敬

问题描述 hdoj 1007 两点之间最短距离的二分之一 提交之后超时了 求c语言解法 感激不敬 #include"stdio.h" #include"math.h" int main() { int n,i,j; double s; while(scanf("%d",&n)&&n) { double a[100000][5]={0}; for(i=0;i<n;i++) for(j=0;j<2;j++) sca

浪潮国际上半年净利1047.5万港元 同比大跌75%

新浪科技讯 9月6日晚间消息,浪潮国际今日发布2012年上半年业绩.报告显示,浪漫国际上半年营业额约为10.7亿港元,较去年同期增长4%:净利润约为1047.5万港元,同比大跌74.89%.IT服务业务营业额约为5.11亿港元,同比减少10.8%,IT服务业务其分类业绩出现亏损约2336.8万港元:IT贸易收入约为5.6亿港元,较去年同期增长22.55%.浪漫国际表示,净利润相对去年同期大幅下降的主要原因有以下两点:1.因市场竞争激烈及整体经济形势较差,导致IT服务业务毛利额仅 同比增长9.58

HDOJ/HDU 1161 Eddy&amp;#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ 2057 A + B Again

Problem Description There must be many A + B problems in our HDOJ , now a new one is coming. Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too. Easy ? AC it ! Input The input contains severa

HDOJ 2033 人见人爱A+B

Problem Description HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱. 这个题目的A和B不是简单的整数,而是两个时间,A和B 都是由3个整数组成,分别表示时分秒,比如,假设A为34 45 56,就表示A所表示的时间是34小时 45分钟 56秒. Input 输入数据有多行组成,首先是一个整数N,表示测试实例的个数,然后是N行数据,每行有6个整数AH,AM,AS,BH,BM,

HDOJ 1001Sum Problem

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + - + n. Input The input will consist of a series of integers n, one integer per line. Output For each ca