1027 Colors in Mars
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red
, the middle 2 digits for Green
, and the last 2 digits for Blue
. The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.
Input Specification:
Each input file contains one test case which occupies a line containing the three decimal color values.
Output Specification:
For each test case you should output the Mars RGB value in the following format: first output #
, then followed by a 6-digit number where all the English characters must be upper-cased. If a single color is only 1-digit long, you must print a 0
to its left.
Sample Input:
15 43 71
Sample Output:
#123456
题意:
给出三个数字将十进制数转化为13进制数字。
思路:
模拟。
Code:
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 int main() { 6 int red, green, blue; 7 cin >> red >> green >> blue; 8 map<int, char> m; 9 m[10] = 'A'; 10 m[11] = 'B'; 11 m[12] = 'C'; 12 string ans = "#"; 13 int x1 = red / 13; 14 if (x1 < 10) 15 ans += to_string(x1); 16 else 17 ans += m[x1]; 18 int x2 = red % 13; 19 if (x2 < 10) 20 ans += to_string(x2); 21 else 22 ans += m[x2]; 23 int y1 = green / 13; 24 if (y1 < 10) 25 ans += to_string(y1); 26 else 27 ans += m[y1]; 28 int y2 = green % 13; 29 if (y2 < 10) 30 ans += to_string(y2); 31 else 32 ans += m[y2]; 33 int z1 = blue / 13; 34 if (z1 < 10) 35 ans += to_string(z1); 36 else 37 ans += m[z1]; 38 int z2 = blue % 13; 39 if (z2 < 10) 40 ans += to_string(z2); 41 else 42 ans += m[z2]; 43 cout << ans << endl; 44 return 0; 45 }