A1027 Colors in Mars (20 分)

#include <iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

char redix[13] = {
    
    
	'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
	'A', 'B', 'C'
};


int main(int argc, char** argv) {
    
    
	
	int a, b, c;
	cin >> a >> b >> c;
	char z1[40], z2[40], z3[40];
	int a1 = 0, a2 = 0, a3 = 0;
	
	do{
    
    
		z1[a1++] = redix[a % 13];
		a /= 13;
	}while(a != 0);
	
	do{
    
    
		z2[a2++] = redix[b % 13];
		b /= 13;
	}while(b != 0);
	
	do{
    
    
		z3[a3++] = redix[c % 13];
		c /= 13;
	}while(c != 0);
	
	cout << "#";
	
	if(a1 == 1){
    
    
		cout << "0";
	}
	
	for(int i = a1-1; i >= 0; i--){
    
    
		cout << z1[i];
	}
	
//	cout << endl;
	
	if(a2 == 1){
    
    
		cout << "0";
	}
	
	for(int i = a2-1; i >= 0; i--){
    
    
		cout << z2[i];
	}
	//	cout << endl;
	if(a3 == 1){
    
    
		cout << "0";
	}
	
	for(int i = a3-1; i >= 0; i--){
    
    
		cout << z3[i];
	}
	//	cout << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/alovelypeach/article/details/113971898