Topcoder SRM 598 div2 A
Problem Statement |
|||||||||||||
| Fox Ciel received a string as a birthday present. However, the string was too long for her, so she decided to make it shorter by erasing some characters. The erasing process will look as follows:
For example, if she receives "cieeilll", she will change the string as follows: "cieeilll" -> "ciilll" -> "clll" -> "cl". You are given a string s. Return the string she will get after she erases characters as described above. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
| - | s will contain between 1 and 50 characters, inclusive. | ||||||||||||
| - | Each character in s will be a lowercase letter ('a'-'z'). | ||||||||||||
Examples |
|||||||||||||
| 0) | |||||||||||||
|
|||||||||||||
| 1) | |||||||||||||
|
|||||||||||||
| 2) | |||||||||||||
|
|||||||||||||
| 3) | |||||||||||||
|
|||||||||||||
| 4) | |||||||||||||
|
|||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
1 #include <cstdio> 2 #include <iostream> 3 #include <vector> 4 #include <set> 5 #include <cstring> 6 #include <string> 7 #include <map> 8 #include <cmath> 9 #include <stack> 10 #include <ctime> 11 #include <algorithm> 12 #include <queue> 13 14 using namespace std; 15 #define INF 0x7fffffff 16 #define maxm 1001 17 #define mod 1000000007 18 #define mp make_pair 19 #define pb push_back 20 #define rep(i,n) for(int i = 0; i < (n); i++) 21 #define re return 22 #define fi first 23 #define se second 24 #define sz(x) ((int) (x).size()) 25 #define all(x) (x).begin(), (x).end() 26 #define sqr(x) ((x) * (x)) 27 #define sqrt(x) sqrt(abs(x)) 28 #define y0 y3487465 29 #define y1 y8687969 30 #define fill(x,y) memset(x,y,sizeof(x)) 31 32 typedef vector<int> vi; 33 typedef long long ll; 34 typedef long double ld; 35 typedef double D; 36 typedef pair<int, int> ii; 37 typedef vector<ii> vii; 38 typedef vector<string> vs; 39 typedef vector<vi> vvi; 40 41 template<class T> T abs(T x) { re x > 0 ? x : -x; } 42 const int maxn = 1015; 43 int n, m, t, k, x, l, r, s, sk,y,top,temp; 44 class ErasingCharacters{ 45 public: 46 string simulate(string s){ 47 for (int i = 0; i < s.length();i++) 48 if (s[i] == s[i + 1])s.erase(s.begin() + i, s.begin() + i + 2), i -= 2; 49 return s; 50 } 51 };
浙公网安备 33010602011771号