| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10673 | Queueing |
|
| 10691 | Simply Fractions 2 |
|
| 10695 | Binary Addition 2 |
|
| 11029 | extend |
|
| 11055 | Vector Intersection |
|
| 11485 | Use std::set |
|
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).
Case1 : #operation <= 10^2, There will be no "Pop" and "Front" command when queue is empty.
Case2 : #operation <= 10^3. There will be no "Pop" and "Front" command when queue is empty.
Case3 : #operation <= 10^4.
Case4 : #operation <= 10^6.
Input
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.
Output
For each “Front” operation, print out the name in the front of the queue.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given several fractions, compute their sum and express the answer in the simplest fraction form.
Input
There are many test cases in one subtask.
The first line of each test case contains an integer t, which indicates the number of fractions in the input. Each of the following t lines contains two integers a and b, which represent the numerator and the denominator of a fraction.
subtask 1 : t=2. 1<=a,b<=10.
subtask 2 : t<=5. 1<=a,b<=10.
subtask 3 : t<=5. 1<=a,b<=50.
subtask 4 : t<=10. 1<=a,b<=100.
Output
Each test case outputs one line.
Namely, you need to add '\n' at the end of each line.
The output is the sum reduced to the simplest fraction form. You need to print a '/' between the numerator and the denominator.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Please compute the sum of two given n-bit binary numbers.
Input
The first line of the input file contains a positive integer t indicating the number of test cases. The first line of each test case is a positive integer n denoting the length of bits. The second and third lines are the two n-bit binary numbers. The first bit of each binary number is always 0, which guarantees that the sum of the two binary numbers can still be expressed as an n-bit binary number.
Case1 : t<=100, n<=100
Case2 : t<=200, n<=1000
Case3 : t<=300, n<=5000
Case4 : t<=400, n<=10000
Output
For each test case, your program should print the sum in the same format as the binary numbers given in input.
Notice that each answer is ended with a newline character.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an integer sequence, say {6, 1, 4, 3, 5, 2}, we can choose any pair of two neighboring numbers (in a circular sense) and swap them to generate a new sequence. For example,
If we choose 6 and 2, we get {2, 1, 4, 3, 5, 6} after swapping.
If we choose 1 and 4, we get {6, 4, 1, 3, 5, 2} after swapping.
Try to generate all possible results for the original sequence, and print the results in lexicographical order. For the example above, the output would be
1 6 4 3 5 2
2 1 4 3 5 6
6 1 3 4 5 2
6 1 4 3 2 5
6 1 4 5 3 2
6 4 1 3 5 2
Hint:
1. Use the set and vector containers.
2. The items in a set will be automatically sorted in lexicographical order.
main
Input
An integer sequence, separated by spaces. End by EOF.
Output
List all possible results for the original sequence in lexicographical order.
Each line contains one sequence, where there is a space between each number.
Note that there is a '\n' at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given two vectors of numbers, output their intersection set.
Note: the numbers of vectors need not to be unique.
Input
There are multiple test cases. Each case contains four lines. The first line begins with an integer N. The second line contains N integers, representing the numbers in the first set. The third line has one integer M, and the fourth line contains M integers, represent the numbers in the second set. All the numbers are 32 bit signed integers. The input is terminated if N = 0.
For case 1, 1 <= N, M <= 103
For case 2, 1 <= N, M <= 104
For case 3, 1 <= N, M <= 105
For case 4, 1 <= N, M <= 106
Output
For each test case, print the intersection of the two sets. Output them in ascending order. If the intersection of the two sets is an empty set, print “empty” (without quotes).
Note: There's a newline character at the end of each output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
This problem will help you understand how to use std::set and comparator.
e.g., std::set<std::vector<int>>
http://en.cppreference.com/w/cpp/container/set
Input
How to compare the integer sequence (calculate the key of an integer sequence):
- get the length of integer sequence (size)
- key value=[first element]*(size)+[second element]*(size-1)+[third element]*(size-2)+...+[last element]*1
- compare the key value. Small key value is smaller.
- if the length of a integer sequence is 0, the key value is 0.
- e.g., the key of an integer sequence "3 9 -1 3 -6" is 48 (3*5+9*4+(-1)*3+3*2+(-6)*1)
The input consist of series of command. Each commands is insert, range_out or output.
insert: inserts an integer sequence (each value is greater than -6 and smaller than 11, stop reading from cin when value is 0). If the key has already existed, then
- output "exist\n"
- erase the integer sequence from set
- reverse the integer sequence (from input)
- insert the reversed integer sequence
For example,
insert 3 9 -1 3 -6 0
The set should contain 3 9 -1 3 -6.
insert 9 -2 6 6 0
The set should contain 6 6 -2 9.
range_out: outputs all integer sequences from the integer sequence (first key) to the integer sequence (second key) of set (including the second key). First key and second key are read from input (each value is greater than -6 and smaller than 11, stop reading from cin when value is 0).
For example,
insert 2 -5 -5 0
insert 3 9 -1 3 -6 0
insert 7 6 1 2 0
insert 10 10 10 2 0
range_out -5 0 10 9 2 0
It should output
3 9 -1 3 -6
7 6 1 2
For example,
insert 2 -5 -5 0
insert 3 9 -1 3 -6 0
insert 7 6 1 2 0
insert 10 10 10 2 0
range_out -5 0 10 10 10 0
It should output
3 9 -1 3 -6
7 6 1 2
output: outputs all integer sequences from the smallest key to the biggest key of set. Output a space character (' ') after printing an integer. Output a newline character ('\n') after printing all elements of a key.
Output
Complete insert, range output and output.