| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 9440 | Stable Sort |
|
| 9444 | Count the Value |
|
| 9448 | Inversion Pair |
|
| 9452 | Queueing |
|
| 9456 | Postfix Evaluation |
|
Description
Given the grades of N people. Please output the sorted result. (Increasing order)
Input
The input includes multiple test cases.
In each test case, the first line contains one integer N. The following N lines specify the name Si and the grade Gi.
The input is terminated by EOF.
For all the cases,
1 <= |Si| <= 10
0 <= Gi <= 100 (Gi is an integer.)
Range of N is different for each case.
Case 1: 1 <= N <= 103
Case 2: 1 <= N <= 104
Case 3: 1 <= N <= 105
Case 4: 1 <= N <= 106
Output
For every test case, output the result in N lines. Every line contains the name and the grade. If more people’s grades are same, output by input order. (That means it uses stable sort.)
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an article, calculate the value of each character and output them in the descending order of their values. The price of characters is calculated as follows: one dollar for a letter ‘a’, two dollars for a letter ‘b’ … and 26 dollars for a letter ‘z’. 'A' and 'a' are not the same in this problem, just count the lowercase letters.
Input
Threr are multiple articles in the input. In each test case, the first line contains one integer, N, which indicates the number of lines in the article.
Note that each line may contains up to 10^7 characters.
Case 1
0 < N <=10
Case 2
0 < N <=50
Case 3
0 < N <=100
Case 4
0 < N <=1000
Output
Output the total value of each character in the descending order. Do not print the character not in the article. If two characters have the same value, output the one with smaller ASCII code first.
Print a blank line after the output of each test case.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
In a number sequence S = {S1, S2, S3, …, Sn}, we called (i,j) an “inversion pair” when Si > Sj and i < j. Given S, calculate the number of inversion pair in this sequence.
Input
There are several numbers of test cases. Each case begins with an integer N in a line, and then N integers N1~Nnfollow, each in a single line. The input is terminated by the number zero.
For case 1, 1<=N<=10, 0<=Ni<=100, the answer <231.
For case 2, 1<=N<=100, 0<=Ni<=106, the answer <231.
For case 3, 1<=N<=1000, -231<=Ni<231, the answer <231.
For case 4, 1<=N<=106 , -231<=Ni<231, the answer <263.
Output
For each test case, print a number of inversion pairs in the given sequence.
Hint: merge sort
Sample Input Download
Sample Output Download
Tags
Discuss
Description
You need to write a program to simulate a queue of names. Each name is a string consisting of English letters only. There are three operations:
1. “Push [name]”, which means to enque name in the queue.
2. “Pop”, which means to deque. If the queue is empty, this operation takes no effect.
3. “Front”, which means to print out the name in the front of queue. If the queue is empty, print "empty" (without quotes).
Input
There will be at most 10^4 names in the queue at a time. However, the number of operations may be much more than that. Each line contains one of the following operations. “Push [name]” (without quotes), “Pop” (without quotes), “Front”(without quotes). The length of each name is at most 10.
Case 1: 0 < #operations < 200
Case 2: 0 < #operations < 20000
Case 3: 0 < #operations < 200000
Case 4: 0 < #operations < 1000000
Output
For each “Front” operation, print out the name in the front of the queue.
Hint: circular queue (You are not able to use too much memory!)
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Evaluate the result of a given numerical expression written in postfix notation.
Input
The first line of the input contains an integer N (N ≤ 1000) which denotes the number of test cases. Each test case begins with an integer M (M ≤ 10000) representing the number of tokens in the expression, followed by M tokens in the next line. Tokens are separated by spaces and the operators contain only “+”, “-”, “*” and “/”; the operands are integers in the range [0, 100]. The division operator “/” here is considered as integral division.
You may assume the syntax of the expression is always valid. However, the case divided-by-zero may occur. If divided-by-zero operation appears in any stage of the evaluation, output "divided by zero". Otherwise, calculate the result of the expression.
The evaluated results (in each stage of the evaluation) will fit in 32-bit signed integers.
Case 1: 1 ≤ N ≤ 10, 1 ≤ M ≤ 10
Case 2: 1 ≤ N ≤ 300, 1 ≤ M ≤ 100
Case 3: 1 ≤ N ≤ 500, 1 ≤ M ≤ 1000
Case 4: 1 ≤ N ≤ 1000, 1 ≤ M ≤ 10000
Output
The output of each test case occupies a line. Each line begins with the test case number “Case i:”, and then a space character followed by the evaluated answer.