| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 9008 | Encryption |
|
| 9020 | Is it a forest? |
|
| 9029 | All combinations |
|
| 9048 | GCD |
|
| 9100 | Parentheses Matching |
|
Description
We can encrypt a string into other string. One method is to put a string into an n×n array first, where n is the smallest number such that n2 is equal to or larger than the length of the string. Each character is put into a cell of the array, from the top left cell of the array and along neighboring cells in the counterclockwise order. The encrypted string is the output of the row major order. For example, the input string "Greed is good", whose length is 13, are put into a 4×4 array, as shown in the following figure.
The output string is "Googrd e sed i".
If the end of the encrypted string are spaces, don't output them. For example, the output of "Bass GG" is "B Ga Gss".

Input
The input consists of multiple lines. Each line is a test case, a string S with length <= 1000. The number of test case is less than 100.
Output
For each test case, output the encrypted string of S.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a graph, output "Yes" if it's a forest, otherwise "No".
Hint: You can use disjoint set or a DFS with adjacency list to solve this problem.
Input
For each case, The first line contains two positive integers N and M (2 <= N <= 1000000), and N denotes the number of node. In the next M lines, there will be two integers A and B, denoting the two end points of an edge (A, B).
Each case is separated by a blank line. The input is terminated by two zeros in place of N and M.
Output
For each case a line, output "Yes" if it's a forest, otherwise "No".
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given N different digits. You have to choose M digits from them to create all possible numbers in ascending order. For example, given 3 digits "4", "5", "6", and M = 2, the possible answers are "45", "46", "54", "56", "64", "65".
Input
The first line contains a positive integer T (T <= 20), which indicates how many cases in the input. Each case starts with two positive integers N and M (1 <= M <= N <= 10), which denote the amount of the digits and the amount of digits of desired numbers. The next line contains exactly n different digits (0~9) separated by blanks.
Output
For each case, first line outputs the case number. Then, output all the possible numbers in ascending order. (See the Sample Output)
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given two positive integers a and b, compute the greatest common divisor (GCD) of a and b. The GCD of a and b is the biggest integer that can divide a and b with no reminder.
Input
First line contains a positive integer t (t<=1000), which indicates the number of test cases in the input. In the next t lines, each line contains two positive integers a, b, which are smaller than or equal to 106.
Output
For each case, output the GCD of a and b in a line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
A string is said to be valid if it matches one of the following rules:
(1) The string is an empty string.
(2) If a string S is valid, then {S}, [S], (S) and <S> are valid.
(3) If strings S1 and S2 are both valid, then S1S2 is valid.
Given a string consisting of parentheses, determine if it is a valid string.
Input
The first line of the input contains an integer N (N ≤ 1000) denoting the number of test cases followed by. Each of the next N lines corresponds to a test case, which contains a string consisting of parentheses, and the maximum string length will be no more than 1000. Note that an empty string (a line which contains the newline character only) may be contained in the input and it should be considered as a valid string according to rule (1).
Output
For each test case, print “Case i:” and then “Yes” or “No” to indicate that the string is valid or not, separated by a space character. i is the test case number starting from 1.