又一版 A+B 浙大计算机研究生复试上机考试-2008年

来源:互联网 发布:双防火墙网络环境搭建 编辑:程序博客网 时间:2024/05/29 14:47

又一版 A+B

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


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
 

Source
浙大计算机研究生复试上机考试-2008年
 

Recommend
 
  浙大计算机研究生复试上机考试-2008年,很水,但是做做还是有点意义的

#include<stdio.h>#include<algorithm>#include<cstring>#include<stack>#include<cstdio>#include<iostream>using namespace std; stack<int> p;int m;void hanshu(int sum){   if(sum==0)   printf("0");   else   {       while(sum>0)       {           p.push(sum%m);           sum=sum/m;       }   }}int main(){    int i,j,a,b;    int sum;    while(scanf("%d",&m)!=EOF)    {        if(m<=0)        break;        scanf("%d%d",&a,&b);        sum=a+b;        hanshu(sum);        while(!p.empty())        {            //printf("%d",p.top());            cout<<p.top();            p.pop();        }        printf("\n");    }    return 0;}


0 0
原创粉丝点击