1031. Hello World for U (20)
Given any string of N (>=5) 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 vertical line with n1 characters, then left to right along the bottom line with n2 characters, and finally bottom-up along the vertical line with n3 characters. And more, we would like U to be as squared as possible — that is, it must be satisfied that n1 = n3 = max { k| k <= n2 for all 3 <= n2 <= N } with n1 + n2 + n3 – 2 = N.

Input Specification:
Each input file contains one test case. Each case contains one string with no less than 5 and no more than 80 characters in a line. The string contains no white space.

Output Specification:
For each test case, print the input string in the shape of U as specified in the description.

Sample Input:
helloworld!

Sample Output:
h      !
e      d
l       l
lowor

题目大意:用所给字符串按U型输出。n1和n3是左右两条竖线从上到下的字符个数,n2是底部横线从左到右的字符个数。
要求:
1. n1 == n3
2. n2 >= n1
3. n1为在满足上述条件的情况下的最大值

PS:感谢github用户@fs19910227提供的pull request~

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class Main {public static void main(String[] args) throws IOException {BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));final char[] chars = reader.readLine().toCharArray();final int length = chars.length + 2;final int rows = length / 3;final int columns = length / 3 + length % 3;final char[][] table = new char[rows][columns];int index = 0;//leftfor (int i = 0; i < rows; i++, index++) {table[i][0] = chars[index];}//bottomfor (int i = 1; i < columns - 1; i++, index++) {table[rows - 1][i] = chars[index];}//rightfor (int i = rows - 1; i >= 0; i--, index++) {table[i][columns - 1] = chars[index];}for (int i = 0; i < rows; i++) {for (int j = 0; j < columns; j++) {char c = table[i][j] == 0 ? ' ' : table[i][j];System.out.printf("%c", c);if (j == columns - 1) {System.out.println();}}}}
}

[Java] 1031. Hello World for U (20)-PAT甲级相关推荐

  1. 1031. Hello World for U (20)-PAT甲级真题

    Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. ...

  2. [Java] 1015. Reversible Primes (20)-PAT甲级

    1015. Reversible Primes (20) A reversible prime in any number system is a prime whose "reverse& ...

  3. 1120. Friend Numbers (20)-PAT甲级真题

    1120. Friend Numbers (20) Two integers are called "friend numbers" if they share the same ...

  4. 1042. Shuffling Machine (20)-PAT甲级真题

    Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...

  5. 1081. Rational Sum (20)-PAT甲级真题

    Given N rational numbers in the form "numerator/denominator", you are supposed to calculat ...

  6. 1077. Kuchiguse (20)-PAT甲级真题

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  7. 1061. Dating (20)-PAT甲级真题

    Sherlock Holmes received a note with some strange strings: "Let's date! 3485djDkxh4hhGE 2984akD ...

  8. 1108. Finding Average (20)-PAT甲级真题

    The basic task is simple: given N real numbers, you are supposed to calculate their average. But wha ...

  9. PAT甲级真题目录(按题型整理)(转自柳神)

    转载自:https://www.liuchuo.net/archives/2502?tdsourcetag=s_pcqq_aiomsg 最短路径 1003. Emergency (25)-PAT甲级真 ...

最新文章

  1. ASP.NET页面跳转
  2. java快速注释怎么配置_详解如何在低版本的Spring中快速实现类似自动配置的功能...
  3. PyPA Creating Documentation
  4. JAVA学习笔记之 Date类和Calendar类的使用
  5. 使用Mac通知中心,生活讯息一眼看尽
  6. 男女洗澡前后区别,太形象了!(文末送书)
  7. ORB特征提取算法解析
  8. 淘宝开源Web服务器Tengine简介
  9. SPDY、HTTP/2、QUIC协议
  10. pdf编辑器怎么使用
  11. 苹果手机怎么编辑word文档_怎么用苹果手机扫描文件转换成Word?这个方法我一定要告诉你...
  12. 程序员培训去哪里?哪里学习程序员
  13. 离职原因该怎么回答?
  14. Mathematica 训练课(3)- 简单图形绘制
  15. Java现在好找工作吗?
  16. java基于ssm+mysql学生课程表现作业评价系统
  17. win10系统之下字母与数字间隔变大的解决办法
  18. 索尼xz Android 内存,索尼XZ2 Compect 简单上手体验,不算好看但...还行?
  19. 新库上线 | CnOpenData·IFR工业机器人数据
  20. 反推计算——猴子吃桃子

热门文章

  1. HDFS-HA的配置-----自动Failover
  2. cocos2D中实现滑动菜单CCScrollView+CCMenu效果,(注意不是cocos2D-x)!!
  3. 10 个最佳的支持触摸操作的 JavaScript 框架
  4. Android应用程序的debug属性
  5. [学习笔记]斯坦纳树
  6. C++ 编译期封装-Pimpl技术
  7. 网站页面间脚本传值 sessionStorage
  8. 求出数组中超过一半的数
  9. 正向运动学和反向运动学
  10. 其他的AdapterView——Spinner