Advertisement
Shuva_Dev

the number of subsequences "QAQ" in the string

Dec 8th, 2022
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define endl "\n"
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int c = 0;
  8.     string s1;
  9.     cin >> s1;
  10.  
  11.     if(s1.size() == 1) {
  12.         cout << 0;
  13.     } else {
  14.         for(int i=0; i<s1.size()-2; i++) {
  15.             if(s1[i] == 'Q') {
  16.                 for(int j=i+1; j<s1.size()-1; j++) {
  17.                     if(s1[j] == 'A') {
  18.                         for(int k = j+1; k<s1.size(); k++) {
  19.                             if(s1[k] == 'Q') {
  20.                                 c++;
  21.                             }
  22.                         }
  23.                     }
  24.                 }
  25.             }
  26.         }
  27.         cout << c;
  28.     }
  29.  
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement