首页 > 代码库 > PAT 1027
PAT 1027
简单题,进制转换
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 }
PAT 1027
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。