VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0

来源:互联网 发布:json encode 汉字 编辑:程序博客网 时间:2024/04/28 00:51
C. String Manipulation 1.0
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of character c from the name. After the user changed his name, he can't undo the change.

For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc".

Polycarpus learned that some user initially registered under nickname t, where t is a concatenation of k copies of string s. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name.

<p< p="" style="color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 21px; "><p< p="">
Input
<p< p="">

The first line contains an integer k (1 ≤ k ≤ 2000). The second line contains a non-empty string s, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer n (0 ≤ n ≤ 20000) — the number of username changes. Each of the next n lines contains the actual changes, one per line. The changes are written as "pi ci" (without the quotes), where pi (1 ≤ pi ≤ 200000) is the number of occurrences of letter cici is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1.

<p< p=""><p< p="">
Output
<p< p="">

Print a single string — the user's final name after all changes are applied to it.

<p< p=""><p< p="">
Sample test(s)
<p< p=""><p< p="">
input
2bac32 a1 b2 c
output
acb
input
1abacaba41 a1 a1 c2 b
output
baa
<p< p=""><p< p="">
Note
<p< p="">

Let's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb".


其实就是个水题。。但是比赛的时候没想到直接用一个数组存放用过的点,

关键是用vector对需要删除的点删除

下面是AC代码:

#include <iostream>#include <string>#include <vector>using namespace std;bool checked[200005];vector<int> occ[26];int main(){int K, N;string os, s = "";cin >> K >> os >> N;for (int i = 0; i < K; i++)s += os;for (int i = 0; i < s.size(); i++) occ[((int) s[i])-97].push_back(i);for (int i = 0; i < N; i++) {int oc, in;char c;cin >> oc >> c;in = ((int) c);checked[occ[in-97][oc-1]] = 1;occ[in-97].erase(occ[in-97].begin()+oc-1);}for (int i = 0; i < s.size(); i++)if (!checked[i]) cout << s[i];cout << endl;}