| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10196 | Length of the longest repeat letters |
|
| 11200 | Tower of Hanoi |
|
| 11607 | BigNumberMulti |
|
| 12034 | Longest Palindrome substring |
|
| 12049 | Prime Problem |
|
Description
The input is a string of letters, for example,
BbBTTttTUuuUUUkk
Find the length of the longest repeat letters. For the above example, the answer is 6, because the longest repeat letters are UuuUUU. Note that we do not have to distinguish uppercases from lowercases, that is, U and u are considered the same.
Hint:
a. Use while((ch=getchar())!='\n') { … } to read the input data.
b. Use another variable prev to remember the previous letter.
c. Include ctype.h so that you can use toupper(ch) to convert ch into uppercase, and then you do not need to take care of the case because every letter is uppercase.
d. The algorithm can be summarized as follows:
while loop: read the current letter and do the loop when the letter is not '\n'
i) convert the letter to uppercase
ii) if the letter is different from the previous one
a. compare the length of the current repeat letter with the longest length we have seen so far; if the length of the current letter is longer, then update the longest length as the new one.
b. update the prev as ch
c. reset the length of the current repeat letter as 1 because we start with a new letter
iii) else
a. increase the length of the current repeat letter by 1
Input
The input is a string of English letters, which can be uppercase or lowercase. There are no whitespaces between the letters, and the input is ended with '\n'.
Output
The output is a number indicating the length of the longest consecutive letters. Be sure to add a newline character '\n' at the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The Tower of Hanoi is a mathematical game puzzle. It consists of three rods, which are A, B and C. The puzzle starts with n disks in ascending order of size on rod A, the smallest at the top.
The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
3. No disk may be placed on top of a smaller disk.
Write a program to simulate the moves of the disks. Print the number of disk which is moved in each step.
For example, if n = 3, the moves of each steps are:
move disk 1 from rod A to rod C
move disk 2 from rod A to rod B
move disk 1 from rod C to rod B
move disk 3 from rod A to rod C
move disk 1 from rod B to rod A
move disk 2 from rod B to rod C
move disk 1 from rod A to rod C
You should print out:
1
2
1
3
1
2
1
HINT : You can modify this sample code and implement the function 'hanoi'
#include <stdio.h>
void hanoi(int n, char A, char B, char C);
int main(){
int n;
scanf("%d", &n);
hanoi(n, 'A', 'B', 'C');
return 0;
}
Input
An integer n (0<n<20), which means the number of disk.
Output
Print out the number of disk which is moved in each step, and there is a '\n' at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Arbitrary-precision arithmetic is a common technique in scientific computing.
When we compute some numbers, the sizes of the outcomes are much bigger than the capacities of ‘int’, ‘long long’, and even ‘__int128_t’. Thus, we always use arrays for simulating our implementation.
Now, we give you two positive integers (including 0) which are not over 2000 digits, please output their multiplication.
Input
There is a positive integer T (1 <= T <= 1000). It means that there are T times of operation.
Continuously, there are T rows. In every row, there are two positive integers (including 0), ‘a’ and ‘b’, which are not over 2000 digits. Please compute the ‘a*b’.
Output
According to each multiplication, please output its outcome and print a new line.
When a X-digit number multiplies a Y-digit number, the digits of the outcome will be less than or equal to X+Y. For convenience, suppose that ‘a’ is X-digit, and ‘b’ is Y-digit, the output should be (X+Y)-digit, and please fill the rest of no number part with 0.
For example, you want to compute 11*11, and the outcome is 121. However, the requirement is to output a 4-digit number, so please output 0121.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given N strings composed of only {'A','T','C','G'}.
That is, for any char c in the string , c == 'A' or c == 'T' or c== 'C' or c== 'G'.
Find the length of longest palindromes substring in the string and output the length.
Input
There is a number N in the first line, indicates that there will be N lines follow.
For the next N lines, each of them contains a string.
It is guaranteed that the length of each given string will not exceed 10000.
Output
For each given string, print a line contains only a integer: the length of Longest palindromes substring of that string.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Give some intergers.
Determine whether they are primes or not.
Input
Give a integer N standing for the number of testcases.
There will be N numbers, P1,P2,...Pn in the next line.
1 ≦ Pi ≦ 1012
Output
For each number, give a line for
"True" if it is a prime.
"False" if it isn't.