Advertisement
kdzhr

Untitled

Jan 7th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. // TL 1st group https://informatics.mccme.ru/mod/statements/view3.php?id=18805&chapterid=113098#1
  2.  
  3. # include <set>
  4. # include <string>
  5. # include <iostream>
  6. # include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. void gen_st(string &s, set<string> &st) {
  11.     size_t n = s.length();
  12.     for (size_t i = 0; i < n; i++) {
  13.         string st_cur;
  14.         st_cur += s[i];
  15.         st.insert(st_cur);
  16.         for (size_t j = i + 1; j < n; j++) {
  17.             st_cur += s[j];
  18.             st.insert(st_cur);
  19.         }
  20.     }
  21. }
  22.  
  23. void gen_posl(string &s, set<string> &posl, string cur_s, size_t k) {
  24.     if (k == s.length()) {
  25.         if (cur_s.length() > 0){
  26.             posl.insert(cur_s);
  27.         }
  28.     } else {
  29.         gen_posl(s, posl, cur_s, k + 1);
  30.         cur_s += s[k];
  31.         gen_posl(s, posl, cur_s, k + 1);
  32.     }
  33. }
  34.  
  35. int32_t check_st(string &s) {
  36.     set<string> st;
  37.     set<string> posl;
  38.     string s_func = "";
  39.     gen_st(s, st);
  40.     gen_posl(s, posl, s_func, 0);
  41.     if (st.size() == posl.size()) {
  42.         return 1;
  43.     }
  44.     else {
  45.         return 0;
  46.     }
  47. }
  48.  
  49. int main() {
  50.     string s;
  51.     int32_t count = 0;
  52.     set<string>check_set;
  53.     cin >> s;
  54.     gen_st(s, check_set);
  55.     for (auto i = check_set.begin(); i != check_set.end(); i++) {
  56.         string cur = *i;
  57.         count += check_st(cur);
  58.     }
  59.     cout << count;
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement