Advertisement
Rofyda_Elghadban1

Untitled

Sep 19th, 2023
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1.  #include <bits/stdc++.h>
  2.  #define ll long long
  3.  #define ull unsigned long long
  4.  #define pi 3.141592654
  5.  #define NUM 1e18
  6.  #define Mod  1'000'000'007
  7.  #define fixed(n) fixed<<setprecision(n)
  8.  #define cin(v) for(auto &i:v) cin >> i ;
  9.  #define cout(v) for(auto &i:v) cout << i  <<" ";
  10.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11.  #define small(x) (x>=97&&x<=122)
  12.  #define capital(x) (x>=65&&x<=90)
  13.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15.  #define all(v) ((v).begin()), ((v).end())
  16.  #define allr(v) ((v).rbegin()), ((v).rend())
  17.  #define updmax(a,b) a=max(a,b)
  18.  #define updmin(a,b) a=min(a,b)
  19.  #define ceil(a,b) ((a/b)+(a%b?1:0))
  20.  /* asc -> 1 2 3 ,des -> 3 2 1 */
  21.  /***********************************************************************************/
  22.  using namespace std;
  23.  void Rofyda_Elghadban(){
  24.   #ifndef ONLINE_JUDGE  
  25.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26.    #endif
  27.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  28.  }
  29.  
  30.  void solve(){
  31.   int t;
  32.   cin>>t;
  33.   while(t--){
  34.     string s;
  35.     cin>>s;
  36.     int freq[123]{},counter1=0,counter2=0,c=0;
  37.     for(int i=0;i<s.size();i++){
  38.       freq[s[i]]++;
  39.       if(s[i+1]==s[i]){
  40.         c++;
  41.       }
  42.     }
  43.     if(c==s.size()-1&&s.size()>1){
  44.       cout<<1<<"\n";
  45.     }else{
  46.       for(int i=0;i<s.size();i++){
  47.         if(freq[s[i]]==1){
  48.           counter1++;
  49.         }else{
  50.           counter2++;
  51.         }
  52.       }
  53.       cout<<(counter1/2)+(counter2/2)<<"\n";
  54.     }
  55.   }
  56.  }
  57.  
  58.  int main(){
  59.  Rofyda_Elghadban();
  60.  solve();
  61.  
  62.  return 0;
  63. }
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement