简单题,进制转换
1 import java.util.*; 2 import java.io.*; 3 4 class FastReader{ 5 BufferedReader reader; 6 StringTokenizer tokenizer; 7 8 public FastReader(InputStream stream){ 9 reader = new BufferedReader(new InputStreamReader(stream)); 10 tokenizer = null; 11 } 12 13 public String next(){ 14 while (tokenizer == null || !tokenizer.hasMoreTokens()){ 15 try{ 16 tokenizer = new StringTokenizer(reader.readLine()); 17 } catch (Exception e){ 18 throw new RuntimeException(e); 19 } 20 } 21 22 return tokenizer.nextToken(); 23 } 24 25 public int next_int(){ 26 return Integer.parseInt(next()); 27 } 28 } 29 30 public class Main { 31 static String convert_base(int color){ 32 char[] tabulate = { 33 ‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘, 34 ‘A‘, ‘B‘, ‘C‘, 35 }; 36 37 StringBuilder res = new StringBuilder(); 38 char low = tabulate[color % 13]; 39 char high = tabulate[color / 13]; 40 41 res.append(high); 42 res.append(low); 43 44 return res.toString(); 45 } 46 47 public static void main(String[] args){ 48 FastReader reader = new FastReader(System.in); 49 int R, G, B; 50 R = reader.next_int(); 51 G = reader.next_int(); 52 B = reader.next_int(); 53 54 StringBuilder res = new StringBuilder(); 55 res.append(‘#‘); 56 res.append(convert_base(R)); 57 res.append(convert_base(G)); 58 res.append(convert_base(B)); 59 60 System.out.println(res); 61 } 62 }
时间: 2024-11-10 07:05:09