A. QAQ
time limit per test
memory limit per test
input
output
“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
input
QAQAQYSYIOIWIN
output
4
input
QAQQQZZYNOIWIN
output
3
题意
求一个字符串中有多少个QAQ,只能是从左往右走。
解题思路
codeforces签到题,暴力水之。
#include<stdio.h>
#include<string.h>
#define maxn 105
char arr[maxn];
int main()
{
gets(arr);
int sum=0,len=strlen(arr);
for(int i=0; i<len; i++)
if(arr[i]=='Q')
for(int j=i+1; j<len; j++)
if(arr[j]=='A')
for(int k=j+1; k<len; k++)
if(arr[k]=='Q') sum++;
printf("%d\n",sum);
return 0;
}