UVa 11716 - Digital Fortress

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

中文網址

以行的順序輸出。

Solution

建好平方數後,算一下要輸出的順序即可。

Code

UVa 11716
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;

int main()
{
int test;
string str;
int square[10001] = {};

for (int i = 1; i <= 100; i++)
square[i*i] = i;

scanf("%d", &test);
getchar();

while (test--)
{
getline(cin, str);
int len = str.length();

int Sqrt = square[len];
if (Sqrt)
{
for (int i = 0; i < Sqrt; i++)
for (int r = 0; r < Sqrt; r++)
putchar(str[i + r*Sqrt]);
putchar('\n');
}
else
puts("INVALID");

}

return 0;
}