Advertisement
kdzhr

Untitled

Jan 7th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. // 41 point C region 2016 first tour
  2.  
  3. # include <set>
  4. # include <string>
  5. # include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int32_t check_st(string &s, set<string> &checked) {
  10.     checked.insert(s);
  11.     bool first = true;
  12.     char pr = s[0];
  13.     for (size_t i = 1; i < s.length(); i++) {
  14.         if (s[i] != pr) {
  15.             if (first) {
  16.                 first = false;
  17.                 pr = s[i];
  18.             } else {
  19.                 return 0;
  20.             }
  21.         }
  22.     }
  23.     return 1;
  24. }
  25.  
  26. int main() {
  27.     string s;
  28.     int32_t count = 0;
  29.     set<string> checked;
  30.     cin >> s;
  31.     for (size_t i = 0; i < s.length(); i++) {
  32.         string st_cur;
  33.         st_cur += s[i];
  34.         if (checked.find(st_cur) == checked.end()){
  35.             count += check_st(st_cur, checked);
  36.         }
  37.         for (size_t j = i + 1; j < s.length(); j++) {
  38.             st_cur += s[j];
  39.             if (checked.find(st_cur) == checked.end()){
  40.                 count += check_st(st_cur, checked);
  41.             }
  42.         }
  43.     }
  44.     cout << count;
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement