forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path894A - QAQ.cpp
65 lines (44 loc) · 1.47 KB
/
894A - QAQ.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!).
illustration by 猫屋 https://twitter.com/nekoyaliu
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input
The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.
Output
Print a single integer — the number of subsequences "QAQ" in the string.
Examples
inputCopy
QAQAQYSYIOIWIN
outputCopy
4
inputCopy
QAQQQZZYNOIWIN
outputCopy
3
Note
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.length();
int cnt = 0;
for(int i = 0; i < n - 2; i++){
if(s[i] == 'Q'){
for(int j = i + 1; j < n - 1; j++){
if(s[j] == 'A'){
for(int k = j + 1; k < n; k++)
if(s[k] == 'Q')
cnt++;
}
}
}
}
cout << cnt;
return 0;
}