| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10475 | Set Intersection |
|
| 10478 | Simply Fractions |
|
| 10576 | Move |
|
| 10579 | Binary Addition |
|
| 10683 | Look and Say |
|
| 10696 | I2P(II)2015 final exam Cheatsheet |
|
Description
Given two sets of numbers, output their intersection set.
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).
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.
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
There are N numbers in a queue. The origin sequence is from 1 to N. (1 is the head). The operation “Move a b” means to move all the numbers in front of a (including a) and then insert them in front of b without changing order. Given several such operations and output the final status of the sequence.
Input
There will be only one test case. The test case begins with an integer N indicating the number of people. There are several operations followed. The format is “Move a b” (without quote) you can assume that the position of a is in front of the position of b. The test case is terminated by “Exit” (without quote).
subtask 1 : 1<=N<=100, you can use O(N) algo for each operation.
subtask 2 : 1<=N<=100, you can use O(N) algo for each operation.
subtask 3 : 1<=N<=100000, you need use O(1) algo for each operation.
subtask 4 : 1<=N<=1000000, you need use O(1) algo for each operation.
Output
Output the numbers from the first one to the last one, and separate two consecutive numbers by a space.
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.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a sequence S of digits and a number k, for example S = “4113” and k = 2.
In the sequence S, there is one 4, followed by two 1, followed by one 3.
Then we can produce a new sequence S’ = 142113.
(note :
“one 4” -> 14
“two 1” -> 21
“one 3” -> 13
)
This is the first round, and we need to do it for k rounds.
The input of i round is the output from i-1 round. (i>1)
When i = 1, the input is sequence S, we will give you.
Now, we want you to print the output after k rounds.
Another example :
S = "323", and k = 1
then we have one 3,followed one 2, and followed one 3
so S' would be "131213"
(note:
"one 3" -> 13
"one 2" -> 12
"one 3" -> 13
)
Input
The input includes multiple test cases.
The first of the input is an integer T (T <= 1000) specifying the number of test cases.
For each case, the first line contains the sequence S.
The second line contains one integer k.
limits
Case 1 : length of S <= 5, 1<=k<=2
Case 2 : length of S <= 100, 1<=k<=2
Case 3 : length of S <= 1000, 1<=k<=10
Case 4 : length of S <= 1000, 1<=k<=10
Output
For each test case outputs one line, the output after k rounds.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
1. How to make cin faster?
std::ios_base::sync_with_stdio(false);
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 <queue>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
// Queueing
using namespace std;
int main()
{
string s;
queue<string> q;
while (cin >> s) {
if (s=="Push") {
cin >> s;
q.push(s);
}
else if (s=="Pop") {
if (q.size()>0)
q.pop();
}
else if (s=="Front") {
if (q.size()==0)
cout << "empty\n";
else
cout<<q.front()<<"\n";
}
}
}
4. 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';
}
5. 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";
}
}
6. 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";
}
7. 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";
}
8. 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