B1027 Colors in Mars (20分)
-
转换RGB,每个十进制的数用十三进制表示,不足两位补上前导零
-
字符串末尾或者头部加上一个字符
temp=(t+'0')+temp与temp+=(t+'0');
前者加号已经运算重载,是字符串加,不能和数字加混用
若要实现往前补字符需重新定义
char c=t+'0';
temp=c+temp;
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
const int MAX=1001;
const int INF=0x3f3f3f3f;
int main()
{
int n;
string s="#";
for(int i=0;i<3;i++)
{
scanf("%d",&n);
string temp="";
while(n!=0)
{
int t=n%13;
if(t>=0&&t<=9)
{
char ans=t+'0';
temp=ans+temp;
}
else
{
char ans=t-10+'A';
temp=ans+temp;
}
n/=13;
}
while(temp.length()<2)
{
temp='0'+temp;
}
s+=temp;
}
cout<<s;
return 0;
}
网友评论