又一版 A+B

来源:互联网 发布:如何查询淘宝店铺排名 编辑:程序博客网 时间:2024/04/29 06:41

又一版 A+B

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13960    Accepted Submission(s): 5315


Problem Description
输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m <10)进制数。



 

Input
输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。
当m为0时输入结束。
 

Output
输出格式:每个测试用例的输出占一行,输出A+B的m进制数。
 

Sample Input
8 1300 482 1 70
 

Sample Output
25041000
 

Author
ZJU
水题……呵呵,我只会水题目前
#include<iostream>#include<stdio.h>using namespace std;int main(){    __int64 A,B;    int m,i,a[10000];    while(scanf("%d",&m))    {          int k=0;        int sum=0;        if(m==0)            break;        scanf("%I64d%I64d",&A,&B);        sum=A+B;        a[k++]=sum%m;//8  2    0001        sum=sum/m;   //2 2   01        while(sum)        {          a[k++]=sum%m;          sum=sum/m;        }        for(i=k-1;i>=0;i--)            cout<<a[i];        cout<<endl;    }    return 0;}


0 0
原创粉丝点击