a+b

#include<iostream>
#include
<string>
#include
<stack>
using namespace std;
int getn(char x){//1-F转为1-15 
    if(x>='0'&&x<='9')    
    
return x-'0';
    
else
    
return x-'A'+10;
}
char getc(int x){//1-15转为1-f 
    if(x<=9)    
    
return x+'0';
    
else
    
return x+'A'-10;
}
void f102x(int temp,int t){//一函数,从10toX进制 
         stack<char> s;
     
if(temp==0){
          s.push(
'0');
      }    
        
if(temp<0){
                cout
<<"-";
                temp
*=-1;
        }    
        
while(temp){
            s.push(getc(temp
%t));
            temp
/=t;
        }
        
while(!s.empty()){
            cout
<<s.top();
            s.pop();
        }
        cout
<<endl;
}
int x210(string x,int f){//x进制to十进制 
    int temp=0;
    
bool isf=false;
    
for(int i=0;i<x.length();i++){
            
if(x[i]=='-'
                     isf
=true;
            
else
                     temp
=temp*f+getn(x[i]);
    }   
    
if(isf) temp*=-1;
    
return temp;
}
int main(){
int n;
string a,b;
    
while(cin>>n>>a>>b){
      
int ret= x210(a,n)+ x210(b,n);//将a b转为10进制相加 
      f102x(ret,n);//再转成n进制输出 
    }
}
posted @ 2008-07-26 13:40  tiny羊  阅读(218)  评论(0)    收藏  举报