1027. Colors in Mars (20)

注意:

         1、字符數組初始化賦值的幾種方法;

         2、STL中string的“ + ”操作

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
char a[13] = {'0','1','2','3','4','5','6','7','8','9','A','B','C'};
//char a[] = "0123456789ABC";
string dec213(int num){
	string s = "";
	if(num < 13){
		s = s + "0" + a[num];
		return s;
//		return "0" + a[num]; 直接返回亂碼,猜測類似於浮點型和整型的計算,輸出格式轉化爲浮點型 
	}
	else{
		s = s + a[num/13] + a[num%13];
		return s;
	}
}
int main(){
	int red, green, blue;
	cin>>red>>green>>blue;
	cout<<"#"<<dec213(red)<<dec213(green)<<dec213(blue);
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章