PAT 1027. Colors in Mars

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;

vector<char> res(int t)
{
	vector<char> v;
	char map[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C'};
	if(t == 0)
		v.push_back('0');
	while(t)
	{
		int tmp = t%13;
		v.push_back(map[tmp]);
		t /= 13;
	}
	return v;
}

void output(vector<char> &v)
{
	if(v.size() == 1)
		cout<<"0"<<v[0];
	else
	{
		for(int i=v.size()-1; i>=0; i--)
			cout<<v[i];
	}
}

int main()
{
	int a1,a2,a3,b1,b2,b3;
	cin>>a1>>a2>>a3;
	vector<char> v1,v2,v3;
	v1 = res(a1);
	v2 = res(a2);
	v3 = res(a3);
	cout<<"#";
	output(v1);
	output(v2);
	output(v3);
	cout<<endl;
	return 0;
}

  

posted @ 2012-12-14 16:59  Frank@609  Views(207)  Comments(0Edit  收藏  举报