首页 > 代码库 > hihocoder 1039

hihocoder 1039

http://hihocoder.com/problemset/problem/1039

string (1)
 string& insert (size_t pos, const string& str);
substring (2)
 string& insert (size_t pos, const string& str, size_t subpos, size_t sublen);
c-string (3)
 string& insert (size_t pos, const char* s);
buffer (4)
 string& insert (size_t pos, const char* s, size_t n);
fill (5)
 string& insert (size_t pos, size_t n, char c);
    void insert (iterator p, size_t n, char c);
single character (6)
iterator insert (iterator p, char c);
range (7)
template <class InputIterator>
   void insert (iterator p, InputIterator first, InputIterator last);
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <string>
 5 #include <vector>
 6 #include <iostream>
 7 using namespace std;
 8 
 9 string str;
10 
11 string deal(string &s)
12 {
13     vector<char> tmp;
14     tmp.push_back(s[0]);
15     int len = s.length();
16     for(int i = 1;i<len-1;i++)
17     {
18         int pre = i-1;
19         while(s[i]==s[i+1])
20             i++;
21         if(i-1==pre)
22             tmp.push_back(s[i]);
23     }
24     return string(tmp.begin(),tmp.end());
25 }
26 
27 int main()
28 {
29     int t;
30     scanf("%d",&t);
31     while(t--)
32     {
33         cin>>str;   
34         int ans = 0;
35         str = "#"+str+"@";
36         for(int i = 1;i<str.size();i++)
37             for(int j = 0;j<3;j++)
38             {
39                 string tmp = str;
40                 tmp.insert(i,1,j+A);
41                 int len = tmp.size();
42                 while(1)
43                 {
44                     tmp = deal(tmp)+"@";
45                     if(tmp.size()<len)
46                         len = tmp.size();
47                     else break;
48                 }
49                 if(str.length()-len+1>ans)
50                     ans = str.length()-len+1;
51             }
52         cout<<ans<<endl;
53     }
54     return 0;
55 }

 

hihocoder 1039