首页 > 其他 > 详细

1027 Colors in Mars (20point(s)) Easy only once

时间:2020-01-15 16:00:57      阅读:78      评论:0      收藏:0      [点我收藏+]

基本思想:

进制转换经典问题;

 

关键点:

关于进制处理,需要注意下这个常用操作;

 

 1 #include<iostream>
 2 #include<stdlib.h>
 3 #include<stdio.h>
 4 #include<vector> 
 5 #include<string>
 6 #include<math.h>
 7 #include<algorithm>
 8 using namespace std;
 9 using std::vector;
10 
11 string trans(int t) {
12     string s;
13     int a;
14     while (t != 0) {
15         a = t % 13;
16         if (a < 10) {
17             s.push_back(0 + a);
18         }
19         else {
20             s.push_back(A + a - 10);
21         }
22         t /= 13;
23     }
24     while (s.size()<2)
25         s.push_back(0);
26     reverse(s.begin(), s.end());;
27     return s;
28 }
29 
30 int main() {
31     int a, b, c;
32     scanf("%d %d %d", &a, &b, &c);
33     cout << "#" << trans(a) << trans(b) << trans(c);
34     system("pause");
35     return 0;
36 }

1027 Colors in Mars (20point(s)) Easy only once

原文:https://www.cnblogs.com/songlinxuan/p/12197135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!