| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11053 | Lexicographic Order |
|
| 11055 | Vector Intersection |
|
| 11071 | Simply Fractions (multiplication) |
|
| 11072 | I2P(II)2020 final exam Cheatsheet |
|
| 11075 | Binary Addition |
|
| 11077 | Queueing |
|
Description
There is a list of English words. Output them in lexicographic order. We compare the first character of two strings S1 and S2. If the ASCII code of the first character of S1 is smaller than the first character of S2, we said that S1 is smaller than S2. Otherwise, if their first characters are the same, we compare their second characters, so on so forth until we can determine their order. If S1 is S2’s prefix, S1 is smaller than S2 and vice versa.
Input
There are multiple test cases. Each case begins with an integer N in a line, and then N words follow, each word in a line. The maximum length of words is 50. The alphabets are 26 small English letters ‘a’ to ‘z’. The input is terminated if N = 0.
Case 1: 1 <= N <= 10
Case 2: 1 <= N <= 100
Case 3: 1 <= N <= 500
Case 4: 1 <= N <= 1000
Output
For each test case, print the words in lexicographic order, one word per line.
Print a blank line after each case.
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
Given several fractions, compute their product (multiplies all fractions) 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.
The output is the product 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
1. How to make cin faster?
std::ios_base::sync_with_stdio(false);
use '\n' instead of endl
2. An example of using <vector>
#include <iostream>
#include <vector>
#include <algorithm> // sort
int main ()
{
std::vector<int> V;
int x;
while (std::cin>>x) {
V.push_back(x);
}
for (auto t : V) std::cout<<" "<< t;
std::cout << "\n";
std::sort(V.begin(), V.end());
for (auto t : V) std::cout<<" "<< t;
std::cout << "\n";
}
3. An example of using <stringstream>
#include <string>
#include <iostream>
#include <sstream> // std::stringstream
int main () {
std::stringstream ss;
ss << "Hello " << 123;
std::string s = ss.str();
std::cout << s << '\n';
}
4. An example of using <set>
#include <iostream>
#include <set>
int main()
{
std::set<int> S = {1, 2, 3, 4};
auto search = S.find(2);
if(search != S.end()) {
std::cout << (*search) << '\n';
}
else {
std::cout << "Not found\n";
}
}
5. An example of using <stack>
#include <stack>
#include <iostream>
int main()
{
std::stack<int> s;
s.push( 3 ); s.push( 6 );
s.push( 18 );
std::cout<<s.size()<<" elements\n";
std::cout<<"Top: "<< s.top()<< "\n";
s.pop();
std::cout<<s.size()<<" elements\n";
}
6. An example of getline()
#include <string>
#include <iostream>
int main()
{
std::string name;
std::cout << "What is your name? ";
std::getline(std::cin, name);
std::cout << "Hello "<< name<< "\n";
}
7. An example of using <map>
#include <iostream>
#include <string>
#include <map>
#include <utility> // make_pair
int main()
{
std::map<std::string, int> ID;
ID.insert(std::make_pair("Tom", 123));
std::cout << ID["Tom"] << "\n";
}
Input
Output
Sample Input Download
Sample Output Download
Tags
Discuss
Description
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.
Level 1 : T<=100, N<=100
Level 2 : T<=200, N<=1000
Level 3 : T<=300, N<=5000
Level 4 : 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.
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).
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. Note that you NEED to add a "\n" at the end.