SHARE
TWEET

Untitled

a guest Nov 23rd, 2014 217 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     freopen("strings.in", "r", stdin);
  10.     freopen("strings.out", "w", stdout);
  11.  
  12.     string s;
  13.     cin >> s;
  14.     int n = s.length();
  15.     vector<vector<int> > v(26);
  16.     int mx = 0;
  17.     for (int i = 0; i < n; i++) v[s[i] - 'a'].push_back(i);
  18.     for (int i = 0; i < 26; i++) mx = max(mx, (int)v[i].size());
  19.     int ans = 1;
  20.     for (int i = 0; i < 26; i++) if (mx == (int)v[i].size()) {
  21.         for (int res = 0; v[i].back() + res < n; res++) {
  22.             bool ok = true;
  23.             for (int j = 0; j < (int)v[i].size(); j++) {
  24.                 ok &= s[v[i][j] + res] == s[v[i][0] + res];
  25.             }
  26.             if (!ok) break;
  27.             ans = max(ans, res + 1);
  28.         }
  29.     }
  30.     cout << ans << endl;
  31.     return 0;
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top