Advertisement
Dang_Quan_10_Tin

MM HSGHN L9 2022-2023

Jan 12th, 2023
943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. constexpr int N = 1e3 + 5;
  6. string s;
  7. vector<string> listString;
  8.  
  9. void Read()
  10. {
  11.     cin >> s;
  12. }
  13.  
  14. bool IsDigit(char c)
  15. {
  16.     return c >= '0' && c <= '9';
  17. }
  18.  
  19. void Solve()
  20. {
  21.     for (int i = 0, j = 0; i < s.length(); i = j)
  22.     {
  23.         // Nếu s[i] và s[j] cùng là chữ số hoặc không cùng là chữ số
  24.         // thì hai kí tự này thuộc cùng một xâu
  25.         while (j < s.length() && IsDigit(s[i]) == IsDigit(s[j]))
  26.             ++j;
  27.  
  28.         string tempString = "";
  29.         for (int t = i; t < j; ++t)
  30.             tempString.push_back(s[t]);
  31.  
  32.         if (IsDigit(tempString[0])) // Nếu xâu chỉ gồm các chữ số
  33.             listString.push_back(tempString);
  34.     }
  35.  
  36.     for (string &number : listString)
  37.     {
  38.         while (number[0] == '0')
  39.             number.erase(0, 1);
  40.     }
  41.  
  42.     int answer = 0;
  43.  
  44.     sort(listString.begin(), listString.end());
  45.  
  46.     for (int i = 0; i < listString.size(); ++i)
  47.         if (i == 0 || listString[i] != listString[i - 1])
  48.             ++answer;
  49.  
  50.     cout << answer;
  51. }
  52.  
  53. int32_t main()
  54. {
  55.     ios::sync_with_stdio(0);
  56.     cin.tie(0);
  57.     cout.tie(0);
  58.     Read();
  59.     Solve();
  60. }
  61.  
  62. /*
  63. abc123abc2a3a1
  64. 4
  65.  
  66. as00023dkrf23smk1asd23sam09aa9
  67. 3
  68. */
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement