Each input file contains one test case which occupies a line containing the three decimal color values.
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 the left.
15 43 71
#123456
package go.jacob.day1026; import java.util.Scanner; /** * 简单题,但要注意,输出的时候每一个颜色固定两位 * @author Administrator * */ public class Demo1 { static char[] c = new char[] { 'A', 'B', 'C' }; public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] color = new String[3]; for (int i = 0; i < 3; i++) { color[i] = solve(sc.nextInt()); } System.out.println("#" + color[0] + color[1] + color[2]); sc.close(); } // 十进制转十三进制 private static String solve(int num) { StringBuilder res = new StringBuilder(); if (num == 0) return "00"; while (num != 0) { int t = num % 13; if (t < 10) res.append(t); else res.append(c[t - 10]); num /= 13; } String r = res.reverse().toString(); if (r.length() == 1) return "0" + r; else return r; } }
import java.util.Scanner; public class Main { public static String convert(int n){ String c[]={"0","1","2","3","4","5","6","7","8","9","A","B","C"}; String s=""; s+=c[n/13]; s+=c[n%13]; return s; } public static void main(String[] args) { Scanner in=new Scanner(System.in); System.out.print("#"); for(int i=0;i<3;i++){ System.out.print(convert(in.nextInt())); } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int r=sc.nextInt(); int g=sc.nextInt(); int b=sc.nextInt(); String marsR=""; if(r<13) marsR+="0"; while(r/13>0){ marsR+=switchNumber(r/13); r-=r/13*13; } marsR+=switchNumber(r%13); String marsG=""; if(g<13) marsG+="0"; while(g/13>0){ marsG+=switchNumber(g/13); g-=g/13*13; } marsG+=switchNumber(g%13); String marsB=""; if(b<13) marsB+="0"; while(b/13>0){ marsB+=switchNumber(b/13); b-=b/13*13; } marsB+=switchNumber(b%13); System.out.println("#"+marsR+""+marsG+""+marsB); } public static String switchNumber(int n){ String result=""; if(n<10){ result+=n; }else{ if(n==10) result+="A"; if(n==11) result+="B"; if(n==12) result+="C"; } return result; } }
#include<iostream>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int m = 13;
string str = "0123456789ABC";
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
printf("#%c%c%c%c%c%c\n", str[a/m],str[a%m],str[b/m],str[b%m], str[c/m], str[c%m]);
system("pause");
return 0;
}
import java.util.ArrayList; import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String str = scanner.nextLine(); String[] arr = str.split(" "); System.out.print("#"); String s = ""; for (int i = 0; i < arr.length; i++) { String ss = Integer.toString(Integer.parseInt(arr[i]),13); if (Integer.parseInt(arr[i])<13) { ss = "0"+ss; } s += ss; } System.out.println(s.toUpperCase()); } } }
// 抄袭了一个itoa的函数 10进制转任意进制转换 #include <iostream> #include <iomanip> using namespace std; char* itoa(int num, char *str, int radix) { /*索引表*/ char index[]="0123456789ABCDEF"; unsigned unum;/*中间变量*/ int i=0,j,k; /*确定unum的值*/ if(radix==10&&num<0)/*十进制负数*/ { unum=(unsigned)-num; str[i++]='-'; } else unum=(unsigned)num;/*其他情况*/ /*转换*/ do{ str[i++]=index[unum%(unsigned)radix]; unum/=radix; }while(unum); str[i]='\0'; /*逆序*/ if(str[0]=='-')k=1;/*十进制负数*/ else k=0; char temp; for(j=k;j<=(i-1)/2;j++) { temp=str[j]; str[j]=str[i-1+k-j]; str[i-1+k-j]=temp; } return str; } int main() { int a,b,c; cin >> a >> b >> c; cout << "#"; char str[100]; itoa(a, str, 13); cout<< setfill('0') << setw(2) << str; itoa(b, str, 13); cout<< setfill('0') << setw(2) << str; itoa(c, str, 13); cout<< setfill('0') << setw(2) << str << endl; }
#include<iostream>
#include<string>
#include<stack>
using namespace std;
void transfer(int input)
{
stack<int> result;
while(1)
{
int left= input%13;
input=input/13;
result.push(left);
//cout<<left<<endl;
if(input==0)
break;
}
if(result.size()==1)
cout<<"0";
while(!result.empty())
{
int top = result.top();
if(top==10)
cout<<"A";
else if(top==11)
cout<<"B";
else if(top==12)
cout<<"C";
else
cout<<top;
result.pop();
}
}
int main()
{
int A,B,C;
scanf("%d %d %d",&A,&B,&C);
cout<<"#";
transfer(A);
transfer(B);
transfer(C);
cout<<endl;
return 0;
}
import java.util.Scanner; public class Main { final static String MarsNum = "0123456789ABC"; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int Red = sc.nextInt(); int Green = sc.nextInt(); int Blue = sc.nextInt(); System.out.println("#"+toMarsNum(Red)+toMarsNum(Green)+toMarsNum(Blue)); } static String toMarsNum(int num){ return ""+MarsNum.charAt(num/13)+MarsNum.charAt(num%13); } }
#include <iostream> #include <cmath> #include <string> #include <iomanip> using namespace std; string trans(int dec) { int m = dec; string mars = ""; while(m / 13 > 0) { int rem = m % 13; if (rem < 10) { mars = to_string(rem) + mars; } else { mars = string(1, 'A' + rem - 10) + mars; } m = m / 13; } if (m < 10) { mars = to_string(m) + mars; } else { mars = string(1, 'A' + m - 10) + mars; } return mars; } int main() { int r, g, b; cin >> r >> g >> b; cout << "#" << setw(2) << setfill('0') << trans(r) << setw(2) << setfill('0') << trans(g) << setw(2) << setfill('0') << trans(b); return 0; }
public class Advanced1006 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String r = Integer.toString(scanner.nextInt(), 13).toUpperCase(); String g = Integer.toString(scanner.nextInt(), 13).toUpperCase(); String b = Integer.toString(scanner.nextInt(), 13).toUpperCase(); scanner.close(); r = r.length() < 2 ? "0" + r : r; g = g.length() < 2 ? "0" + g : g; b = b.length() < 2 ? "0" + b : b; System.out.println("#" + r + g + b); } }
#include <cstdio> int main() { int c[3]; char c13[6] = {'0', '0', '0', '0', '0', '0'}; scanf("%d%d%d", &c[0], &c[1], &c[2]); for(int i = 0; i < 3; i++) { int temp, num = 0; do { temp = c[i] % 13; if(temp >= 10) c13[i * 2 + num++] = 'A' + (temp - 10); else c13[i * 2 + num++] = '0' + temp; c[i] /= 13; } while(c[i] != 0); } printf("#"); for(int i = 0; i < 3; i++) { printf("%c%c", c13[i * 2 + 1], c13[i * 2]); } return 0; }
import java.util.Scanner; public class Main { static char[]nums={'0','1','2','3','4','5','6','7','8','9','A','B','C'}; public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String[] line=scanner.nextLine().trim().split(" "); StringBuilder builder=new StringBuilder(); builder.append("#"); for(String dec :line){ int val=Integer.parseInt(dec); builder.append(nums[val/13]); builder.append(nums[val%13]); } System.out.println(builder.toString()); } }
#include<bits/stdc++.h> using namespace std; void trans(int n){ int a = n/13; int b = n%13; (0 <= a && a <= 9) ? printf("%d", a) : printf("%c", ('A'+a-10)); (0 <= b && b <= 9) ? printf("%d", b) : printf("%c", ('A'+b-10)); } int main() { int r, g, b; scanf("%d %d %d", &r, &g, &b); printf("#");trans(r); trans(g);trans(b); return 0; }
#include"string" #include"vector" #include"iostream" using std::string; using std::vector; using std::cin; using std::cout; vector<string> radix13 = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C" }; string temp = "#"; void MarsColor(); int main() { MarsColor(); return 0; } void MarsColor() { int R, G, B; cin >> R >> G >> B; temp += radix13[R / 13] + radix13[R % 13] + radix13[G / 13] + radix13[G % 13] + radix13[B / 13] + radix13[B % 13]; cout << temp; }