zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    php 数据库练习之租房子
    php数据访问之查询关键字
    Objective-C代码学习大纲(3)
    Objective-C代码学习大纲(2)
    Objective-C代码学习大纲(1)
    简介Objective-C语言
    为什么Objective-C很难
    Swift之 ? 和 !
    使用Mac App Store更新、下载软件时出现未知错误的解决方法
    如何激励用户为你的app评分?
  • 原文地址:https://www.cnblogs.com/EpisodeXI/p/4067947.html
Copyright © 2011-2022 走看看