fork download
  1. /*
  2. プログラミングのお題スレ Part15
  3. //mevius.5ch.net/test/read.cgi/tech/1564310397/696
  4.  
  5. 696 名前:デフォルトの名無しさん[] 投稿日:2019/10/06(日) 05:37:10.28 ID:oevqPO9x
  6. お題: L形図形を表示する
  7. [入力]
  8. 1
  9. [出力]
  10. a
  11. bc
  12.  
  13. [入力]
  14. 2
  15. [出力]
  16. ba
  17. ca
  18. abcc
  19. bcab
  20.  
  21. [入力]
  22. 3
  23. [出力]
  24. bacb
  25. cbaa
  26. acba
  27. bcca
  28. bcabcccb // 正しくはbaabcccbのはず
  29. cabcabca
  30. abccaabc
  31. bcabbcab
  32. */
  33. class Ideone
  34. {
  35. public static void main(String[] args)
  36. {
  37. show(1);
  38. show(2);
  39. show(3);
  40. show(4);
  41. }
  42.  
  43. static void show(int input)
  44. {
  45. if (input < 1) throw new IllegalArgumentException();
  46. System.out.printf("[入力]%n%d%n", input);
  47. char[][] data = { { 'a' }, { 'b', 'c' } };
  48. while (--input > 0)
  49. {
  50. data = next(data);
  51. }
  52. System.out.printf("[出力]%n%s%n", toString(data));
  53. }
  54.  
  55. static char[][] next(char[][] data)
  56. {
  57. int l = data.length;
  58. int h = l >> 1;
  59. int d = l << 1;
  60.  
  61. char[][] next = new char[l * 2][];
  62. for (int i = 0; i < data.length; i++)
  63. {
  64. next[i] = new char[l];
  65. next[i + l] = new char[l * 2];
  66. }
  67.  
  68. for (int y = 0; y < data.length; y++)
  69. {
  70. for (int x = 0; x < data[y].length; x++)
  71. {
  72. next[y + h][x + h] = data[y][x];
  73. next[x][l - y - 1] = data[y][x];
  74. next[y + l][x] = data[y][x];
  75. next[d - x - 1][y + l] = data[y][x];
  76. }
  77. }
  78. return next;
  79. }
  80.  
  81. static String toString(char[][] data)
  82. {
  83. StringBuilder sb = new StringBuilder();
  84. for (char[] cs : data)
  85. {
  86. sb.append(cs);
  87. sb.append(System.lineSeparator());
  88. }
  89. return sb.toString();
  90. }
  91. }
Success #stdin #stdout 0.09s 34036KB
stdin
Standard input is empty
stdout
[入力]
1
[出力]
a
bc

[入力]
2
[出力]
ba
ca
abcc
bcab

[入力]
3
[出力]
bacb
cbaa
acba
bcca
baabcccb
cabcabca
abccaabc
bcabbcab

[入力]
4
[出力]
bacbbacb
cbaaccba
acbacbac
bccbaaab
baacbacb
cabccbaa
abccacba
bcabbcca
bacbbaabcccbbacb
cbaacabcabcaccba
acbaabccaabccbac
bccabcabbcabcaab
baabcccbbaaabccb
cabcabcacabcabca
abccaabcabccaabc
bcabbcabbcabbcab