PAT甲級 1027 Colors in Mars (20分)

又是進制轉換和字符串的應用,簡單的題,詳細看代碼把。

#include<bits/stdc++.h>
using namespace std;
string into(int x)
{
	string temp;
	if(x==0)
	return "00";
	while(x)
	{
		int p;
		p = x%13;
		if(p>9)
		temp += p-10+'A';
		else
		temp += p+'0';
		x = x/13;
	}
	if(temp.length()==1)
	temp += '0';
	reverse(temp.begin(),temp.end());
	
	return temp;
}
main()
{
	int red,green,blue;
	cin>>red>>green>>blue;
	printf("#");
	string out_red,out_green,out_blue;
	out_red = into(red);
	out_green = into(green);
	out_blue = into(blue);
	cout<<out_red<<out_green<<out_blue;
 } 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章