Dang_Quan_10_Tin

DAYK TS10 PTNK 2007-2008

Jan 15th, 2022
759
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define task "DAYK"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. using ll = long long;
  10. using ld = long double;
  11.  
  12. constexpr int N = 1e5 + 5;
  13. string s;
  14. int n;
  15.  
  16. void Read()
  17. {
  18.     cin >> n >> s;
  19.     s = " " + s;
  20. }
  21.  
  22. // Tìm k
  23. int Get(const string &s)
  24. {
  25.     for (int i = (int)s.size(); i; --i)
  26.     {
  27.         string p = s.substr(s.size() - i, i);
  28.         reverse(p.begin(), p.end()); // i kí tự đọc ngược từ cuối về
  29.  
  30.         if (p == s.substr(0, i))
  31.             return i;
  32.     }
  33.  
  34.     return 0;
  35. }
  36.  
  37. void Solve()
  38. {
  39.     for (int i = 1; i <= n; ++i)
  40.         cout << Get(s.substr(1, i)) << " ";
  41. }
  42.  
  43. int32_t main()
  44. {
  45.     ios::sync_with_stdio(0);
  46.     cin.tie(0);
  47.     cout.tie(0);
  48.     if (fopen(task ".INP", "r"))
  49.     {
  50.         freopen(task ".INP", "r", stdin);
  51.         freopen(task ".OUT", "w", stdout);
  52.     }
  53.  
  54.     Read();
  55.     Solve();
  56. }
  57.  
RAW Paste Data