/*
プログラミングのお題スレ Part15
//mevius.5ch.net/test/read.cgi/tech/1564310397/696
696 名前:デフォルトの名無しさん[] 投稿日:2019/10/06(日) 05:37:10.28 ID:oevqPO9x
お題: L形図形を表示する
[入力]
1
[出力]
a
bc
[入力]
2
[出力]
ba
ca
abcc
bcab
[入力]
3
[出力]
bacb
cbaa
acba
bcca
bcabcccb // 正しくはbaabcccbのはず
cabcabca
abccaabc
bcabbcab
*/
class Ideone
{
public static void main
(String[] args
) {
show(1);
show(2);
show(3);
show(4);
}
static void show(int input)
{
System.
out.
printf("[入力]%n%d%n", input
); char[][] data = { { 'a' }, { 'b', 'c' } };
while (--input > 0)
{
data = next(data);
}
System.
out.
printf("[出力]%n%s%n", toString
(data
)); }
static char[][] next(char[][] data)
{
int l = data.length;
int h = l >> 1;
int d = l << 1;
char[][] next = new char[l * 2][];
for (int i = 0; i < data.length; i++)
{
next[i] = new char[l];
next[i + l] = new char[l * 2];
}
for (int y = 0; y < data.length; y++)
{
for (int x = 0; x < data[y].length; x++)
{
next[y + h][x + h] = data[y][x];
next[x][l - y - 1] = data[y][x];
next[y + l][x] = data[y][x];
next[d - x - 1][y + l] = data[y][x];
}
}
return next;
}
static String toString
(char[][] data
) {
StringBuilder sb = new StringBuilder();
for (char[] cs : data)
{
sb.append(cs);
sb.
append(System.
lineSeparator()); }
return sb.toString();
}
}
LyoK44OX44Ot44Kw44Op44Of44Oz44Kw44Gu44GK6aGM44K544OsIFBhcnQxNSAKLy9tZXZpdXMuNWNoLm5ldC90ZXN0L3JlYWQuY2dpL3RlY2gvMTU2NDMxMDM5Ny82OTYKCjY5NiDlkI3liY3vvJrjg4fjg5Xjgqnjg6vjg4jjga7lkI3nhKHjgZfjgZXjgpNbXSDmipXnqL/ml6XvvJoyMDE5LzEwLzA2KOaXpSkgMDU6Mzc6MTAuMjggSUQ6b2V2cVBPOXgK44GK6aGMOiBM5b2i5Zuz5b2i44KS6KGo56S644GZ44KLClvlhaXliptdCjEKW+WHuuWKm10KYQpiYwoKW+WFpeWKm10KMgpb5Ye65YqbXQpiYQpjYQphYmNjCmJjYWIKClvlhaXliptdCjMKW+WHuuWKm10KYmFjYgpjYmFhCmFjYmEKYmNjYQpiY2FiY2NjYiAvLyDmraPjgZfjgY/jga9iYWFiY2NjYuOBruOBr+OBmgpjYWJjYWJjYQphYmNjYWFiYwpiY2FiYmNhYgoqLwpjbGFzcyBJZGVvbmUKewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykKICAgIHsKICAgICAgICBzaG93KDEpOwogICAgICAgIHNob3coMik7CiAgICAgICAgc2hvdygzKTsKICAgICAgICBzaG93KDQpOwogICAgfQogICAgCiAgICBzdGF0aWMgdm9pZCBzaG93KGludCBpbnB1dCkKICAgIHsKICAgICAgICBpZiAoaW5wdXQgPCAxKSB0aHJvdyBuZXcgSWxsZWdhbEFyZ3VtZW50RXhjZXB0aW9uKCk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGYoIlvlhaXliptdJW4lZCVuIiwgaW5wdXQpOwogICAgICAgIGNoYXJbXVtdIGRhdGEgPSB7IHsgJ2EnIH0sIHsgJ2InLCAnYycgfSB9OwogICAgICAgIHdoaWxlICgtLWlucHV0ID4gMCkKICAgICAgICB7CiAgICAgICAgICAgIGRhdGEgPSBuZXh0KGRhdGEpOwogICAgICAgIH0KICAgICAgICBTeXN0ZW0ub3V0LnByaW50ZigiW+WHuuWKm10lbiVzJW4iLCB0b1N0cmluZyhkYXRhKSk7CiAgICB9CgogICAgc3RhdGljIGNoYXJbXVtdIG5leHQoY2hhcltdW10gZGF0YSkKICAgIHsKICAgICAgICBpbnQgbCA9IGRhdGEubGVuZ3RoOwogICAgICAgIGludCBoID0gbCA+PiAxOwogICAgICAgIGludCBkID0gbCA8PCAxOwogICAgICAgIAogICAgICAgIGNoYXJbXVtdIG5leHQgPSBuZXcgY2hhcltsICogMl1bXTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGRhdGEubGVuZ3RoOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBuZXh0W2ldID0gbmV3IGNoYXJbbF07CiAgICAgICAgICAgIG5leHRbaSArIGxdID0gbmV3IGNoYXJbbCAqIDJdOwogICAgICAgIH0KCiAgICAgICAgZm9yIChpbnQgeSA9IDA7IHkgPCBkYXRhLmxlbmd0aDsgeSsrKQogICAgICAgIHsKICAgICAgICAgICAgZm9yIChpbnQgeCA9IDA7IHggPCBkYXRhW3ldLmxlbmd0aDsgeCsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBuZXh0W3kgKyBoXVt4ICsgaF0gPSBkYXRhW3ldW3hdOwogICAgICAgICAgICAgICAgbmV4dFt4XVtsIC0geSAtIDFdID0gZGF0YVt5XVt4XTsKICAgICAgICAgICAgICAgIG5leHRbeSArIGxdW3hdID0gZGF0YVt5XVt4XTsKICAgICAgICAgICAgICAgIG5leHRbZCAtIHggLSAxXVt5ICsgbF0gPSBkYXRhW3ldW3hdOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBuZXh0OwogICAgfQoKICAgIHN0YXRpYyBTdHJpbmcgdG9TdHJpbmcoY2hhcltdW10gZGF0YSkKICAgIHsKICAgICAgICBTdHJpbmdCdWlsZGVyIHNiID0gbmV3IFN0cmluZ0J1aWxkZXIoKTsKICAgICAgICBmb3IgKGNoYXJbXSBjcyA6IGRhdGEpCiAgICAgICAgewogICAgICAgICAgICBzYi5hcHBlbmQoY3MpOwogICAgICAgICAgICBzYi5hcHBlbmQoU3lzdGVtLmxpbmVTZXBhcmF0b3IoKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzYi50b1N0cmluZygpOwogICAgfQp9