PAT 1031

简单题,字符串处理,注意index就可以了

 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), 1 << 10);
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 long next_long(){
26         return Long.parseLong(next());
27     }
28
29     public int next_int(){
30         return Integer.parseInt(next());
31     }
32 }
33
34 public class Main {
35     public static void main(String[] args){
36         FastReader reader = new FastReader(System.in);
37         String process_str = reader.next();
38
39         int size = process_str.length() + 2;
40         int n1, n2, n3;
41
42         n1 = n3 = size / 3;
43         n2 = n1 + size % 3;
44         size -= 2;
45
46         StringBuilder white_space = new StringBuilder();
47         for (int i = 0; i < n2 - 2; i++)
48             white_space.append(‘ ‘);
49
50         for (int i = 0; i < n1 - 1; i++)
51             System.out.println(process_str.charAt(i) + white_space.toString() + process_str.charAt(size - i - 1));
52         for (int i = n1 - 1; i <= size - n1; i++)
53             System.out.print(process_str.charAt(i));
54         System.out.println();
55     }
56 }
时间: 2024-10-13 06:27:45

PAT 1031的相关文章

PAT 1031. 查验身份证(15)

一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}:然后将计算的和对11取模得到值Z:最后按照以下关系对应Z值与校验码M的值: Z:0 1 2 3 4 5 6 7 8 9 10 M:1 0 X 9 8 7 6 5 4 3 2 现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码. 输入格式: 输入第一行给出正整数N(<= 10

PAT 1031 Hello World for U

#include <cstdio> #include <cstring> #include <cstdlib> using namespace std; char line[82]; char space[82]; int main() { scanf("%s", line); int len = strlen(line); int side_size = (len + 2) / 3 - 1; int last_size = len - side_s

PAT乙级1031

题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 题解 emmm.对于每个身份证号,判断前17位是否合法,并计算其与对应权重积之和,最后判断校验位是否合法. // PAT BasicLevel 1031 // https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 #include

PAT Basic 1031

1031 查验身份证(15)(15 分) 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}:然后将计算的和对11取模得到值Z:最后按照以下关系对应Z值与校验码M的值: Z:0 1 2 3 4 5 6 7 8 9 10\ M:1 0 X 9 8 7 6 5 4 3 2 现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码. 输

PAT——乙级1006:换个格式输出整数&amp;乙级1021:个位数统计&amp;乙级1031:查验身份证

1006 换个格式输出整数 (15 point(s)) 让我们用字母 B 来表示"百".字母 S 表示"十",用 12...n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 3 位的正整数.例如 234 应该被输出为 BBSSS1234,因为它有 2 个"百".3 个"十".以及个位的 4. 输入格式: 每个测试输入包含 1 个测试用例,给出正整数 n(<1000). 输出格式: 每个测试用例的

PAT:1031. 查验身份证(15) AC

#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int weight[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; char M[15]={'1','0','X','9','8','7','6','5','4','3','2'}; int n; bool TAG=true; //是否全都没问题的标志 scanf("%d",

PAT 甲级 1031 Hello World for U

https://pintia.cn/problem-sets/994805342720868352/problems/994805462535356416 Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as: h d e l l r lowo That is, the cha

【PAT甲级】1031 Hello World for U (20 分)

题意: 输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等. trick: 不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是' ',空格的ascii是32,初读题面时并没有看到要输出空格,因为打印0其实效果看起来好像一样... 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;string s;char a[87][87

PAT Advanced 1031 Hello World for U (20分)

Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as: h d e l l r lowo That is, the characters must be printed in the original order, starting top-down from the left