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 }
时间: 2024-11-10 07:05:09

PAT 1027的相关文章

PAT 1027 Colors in Mars

#include <cstdio> #include <iostream> #include <cstdlib> using namespace std; char tbl[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'}; void d213(int d, int &m, int &l) { l = d % 13; m = d / 13; } void prin

PAT 1027. 打印沙漏(20)

本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ***** 所谓"沙漏形状",是指每行输出奇数个符号:各行符号中心对齐:相邻两行符号数差2:符号数先从大到小顺序递减到1,再从小到大顺序递增:首尾符号数相等. 给定任意N个符号,不一定能正好组成一个沙漏.要求打印出的沙漏能用掉尽可能多的符号. 输入格式: 输入在一行给出1个正整数N(<=1000)和一个符号,中间以空格分隔. 输出格式: 首

PAT (Basic Level) Practise (中文)1027. 打印沙漏(20)

1027. 打印沙漏(20) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号:各行符号中心对齐:相邻两行符号数差2:符号数先从大到小顺序递减到1,再从小到大顺序递增:首尾符号数相等. 给定任意N个符号,不一定能正好组成一个沙漏.要求打印出

PAT:1027. 打印沙漏(20) AC

#include int main() { int n; char xing; scanf("%d %c",&n,&xing); int num=1,i=1; while(1) { num = num + 2 * (i + 2); //一开始就超出,不改变i if(num > n) break; i += 2; } int MAX=i; for(int k=0 ; kPAT:1027. 打印沙漏(20) AC

1027. Colors in Mars (20)【进制转换】——PAT (Advanced Level) Practise

题目信息 1027. Colors in Mars (20) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Re

PAT 乙级 1027 打印沙漏(20) C++版

1027. 打印沙漏(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ***** 所谓"沙漏形状",是指每行输出奇数个符号:各行符号中心对齐:相邻两行符号数差2:符号数先从大到小顺序递减到1,再从小到大顺序递增:首尾符号数相等. 给定任意N个符号,不一定

PAT 甲级 1027 Colors in Mars (20 分)

1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the

PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)

1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the

pat(B) 1027. 打印沙漏(输入输出)

1.memset(s,c,sizeof(s));c是char型变量. 2.strncpy(s2,s1,r);把s1的前r个字符复制到s2的前r个中,但在s2的末尾不会自动添加'\0'. 3.strcpy(s2,s1);把s1的字符复制到s2中,但在s2的末尾会自动添加'\0'. 4.代码: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace