• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

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:
         
               
  1.               Find the smallest i such that the i-th character and the               (i+1)-th character of the string are same.            
  2.            
  3.               If there is no such i, end the process.            
  4.            
  5.               Remove the i-th and the (i+1)-th character of the string, and               repeat from 1.            
  6.          
         
         
          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          

       
                                                                                                                                                                                                                                                                                                                                                    
                Class:                               ErasingCharacters              
                Method:                               simulate              
                Parameters:                               string              
                Returns:                               string              
                Method signature:                               string simulate(string s)              
                (be sure your method is public)              
       
                      
                 
         

            Constraints          

       
          -                   s will contain between 1 and 50 characters, inclusive.        
          -                   Each character in s will be a lowercase letter ('a'-'z').        
         

            Examples          

       
          0)                          
                                                                                                                                                            
                                                                                       
                     
"cieeilll"
                   
             
               
Returns: "cl"
             
                                                                                       
                      This is the example from the statement.                    
             
       
          1)                          
                                                                                                                                                            
                                                                                       
                     
"topcoder"
                   
             
               
Returns: "topcoder"
             
                                                                                       
                      She won't erase any characters at all.                    
             
       
          2)                          
                                                                                                                                                            
                                                                                       
                     
"abcdefghijklmnopqrstuvwxyyxwvutsrqponmlkjihgfedcba"
                   
             
               
Returns: ""
             
                                                                                       
                                         
             
       
          3)                          
                                                                                                                                                            
                                                                                       
                     
"bacaabaccbaaccabbcabbacabcbba"
                   
             
               
Returns: "bacbaca"
             
                                                                                       
                                         
             
       
          4)                          
                                                                                                                                                            
                                                                                       
                     
"eel"
                   
             
               
Returns: "l"
             
                                                                                       
                                         
             
       

   

      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 };
View Code
posted @ 2013-12-01 22:54  HaibaraAi  阅读(166)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3