简单题,字符串处理,注意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 }