hdu 1877 hdoj 1877

又一版 A+B

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


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 48 2 1 7 0
 

Sample Output
2504 1000


#include<iostream>
    using namespace std;

    int main(){
        int result[50];
        long a,b,m,n;
        long long c;
        while(cin>>m,m!=0){
            cin>>a>>b;
            c=a+b;
            n=0;
            if(c==0){
                cout<<0<<endl;
                continue;
            }
            while(c){
               result[n]=c%m;
               c/=m;
               n++;
            }
            for(int i=n-1;i>=0;i--){
                cout<<result[i];
            }
            cout<<endl;
        }
        return 0;
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章