HDOJ 1002

简介: 点击打开链接 读入用字符串,然后保存到数组里面(从后面往前存),然后利用数组每一位进行相加,输出时候要逆向输出 #include#include#include#include#includeusing namespac...

点击打开链接


读入用字符串,然后保存到数组里面(从后面往前存),然后利用数组每一位进行相加,输出时候要逆向输出


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    int t,len,s;
    int l1,l2;
    int j,k;
    int sum[1010],a[1010],b[1010];
    string str1,str2;
    char ch='0';
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>str1>>str2;
        l1=str1.size();
        l2=str2.size();
        memset(sum,0,sizeof(sum));
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(k=0,j=l1-1;j>=0;j--)
            a[j]=str1[k++]-48;
        for(k=0,j=l2-1;j>=0;j--)
            b[j]=str2[k++]-48;       
        len=0;
        int max=l1>l2?l1:l2;
        for(j=0,k=0;j<max&&k<max;j++,k++,len++){
            sum[len]+=(a[j]+b[k]);
            if(sum[len]>=10){
               sum[len]=sum[len]%10;
               sum[len+1]++;
            }            
        }
        cout<<"Case "<<i<<":"<<endl;
        for(j=l1-1;j>=0;j--)
            cout<<a[j];
        cout<<" + ";
        for(j=l2-1;j>=0;j--)
            cout<<b[j];
        cout<<" = ";
        for(j=len-1;j>=0;j--)
            cout<<sum[j];
        cout<<endl;
        if(i!=t)
            cout<<endl;
    }
    return 0;
}



目录
相关文章
HDOJ 1214 圆桌会议
HDOJ 1214 圆桌会议
78 0
HDOJ 2033 人见人爱A+B
HDOJ 2033 人见人爱A+B
130 0
HDOJ 2056 Rectangles
HDOJ 2056 Rectangles
110 0
HDOJ 1323 Perfection(简单题)
Problem Description From the article Number Theory in the 1994 Microsoft Encarta: “If a, b, c are integers such that a = bc, a is called a...
817 0
HDOJ 2802 F(N)
Problem Description Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1
699 0
|
Java
HDOJ 1234
开门人和关门人 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7142    Accepted Submission(s): 3656 Problem Description 每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。
767 0