1891 - I2P(II) 2019_Fall_Chen_final Scoreboard

Time

2020/01/09 18:30:00 2020/01/09 21:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10673 Queueing
10683 Look and Say
11055 Vector Intersection
11996 01_Parentheses with Precedence
11997 K Characters with Paddings
12558 I2P(II) Chen_cpp_cheatsheet

10673 - Queueing   

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




10683 - Look and Say   

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




11055 - Vector Intersection   

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




11996 - 01_Parentheses with Precedence   

Description

A string of parentheses is said to be valid if it satisfies one of the following rules:

(1) The string is an empty string.

(2) If strings S and T are both valid, then ST is valid.

(3) If a string S is valid, then {S}, [S], (S) and <S> are valid as long as S does not contain any parentheses with higher precedence than its enclosing parentheses. The precedence order of parentheses from high to low is { }, [ ], ( ), < >.  Therefore, a string of {[]()} is valid, but a string of {([])} is not.

Given a string consisting of parentheses, determine if it is a valid string.

Input

The first line of the input contains an integer N (N ≤ 10000) denoting the number of test cases. Each of the next N lines corresponds to a test case, which contains a string of parentheses, and the maximum string length is no more than 1000 characters. Note that an empty string (a line which contains the newline character only) may be present in the input and it should be considered as a valid string according to rule (1).

Difficulty level 1: N <= 10

Difficulty level 2: N <= 50

Difficulty level 3: N <= 100

Difficulty level 4: N <= 1000

Difficulty level 5: N <= 10000

Output

For each test case, print in each line a "Yes" or a "No" to indicate that the string is valid or not. 

Sample Input  Download

Sample Output  Download

Tags




Discuss




11997 - K Characters with Paddings   

Description

Given a string S, generate all different possible set of K characters in the string with P paddings, and sort them in lexicographic (dictionary) order. A padding is expressed as an underline '_'. For example, if K=2 and P=1, and the given string S is ‘CDBABBD’, the output would be

_AB

_AC

_AD

_BB

_BC

_BD

_CD

_DD

A_B

A_C

A_D

B_B

B_C

B_D

C_D

D_D

AB_

AC_

AD_

BB_

BC_

BD_

CD_

DD_

Input

The first line of input contains a positive integer T (T <= 30), which indicates the number of test cases.

For each case, there is a string S (length| <= 100), a positive integer K (K <= 10), and a nonnegative integer P (P <= 3) in a line. The length of S is less than or equal to 100 and S contains only 'A'-'J'; The number K, less than or equal to 10, indicates the number of non-padding characters in an output set. The nonnegative integer P indicates the number of paddings.

Output

For each test case, print in each line all different possible sets of K characters in the string with P paddings. The answers have to be sorted in the dictionary order, one substring per line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




12558 - I2P(II) Chen_cpp_cheatsheet   

Description

I/O optimization

If you encounter a TLE, you may try to use this optimization for C++ I/O functions:
std::ios_base::sync_with_stdio(false);
cin.tie(0);
And replace all std::endl with '\n'.
Do note that you must not use any of C I/O functions such as scanf, printf, fgets if you use this optimization.

<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";
}

<queue>

#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
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";
        }
    }
}

<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';
}

<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";
     }
}

<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";
}

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";
}

<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";
}

<string>

#include <iostream>
#include <string>
int main() {
    std::string str1, str2, out;
    while (std::cin >> str1 >> str2) {
        out.clear();
        for(auto t : str1) out.push_back(t);
        std::cout << out << '\n';
        out += str2;
        std::cout << out << '\n';
        out.pop_back();
        std::cout << out << '\n';
        for(size_t i = 0; i < out.size(); i++)
            std::cout << out[i];
        std::cout << '\n';
    }
}

Miscellaneous

For more standard library or C++ reference, please refer to this file and rename the downloaded file(12534.cpp) to reference.zip, then unzip it. There's a readme inside the zip.

If you have difficulty renaming file, try the following command on terminal (Windows)

move 12534.cpp reference.zip

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss