codeforces 894 A题 QAQ -mystical_curve
来源:互联网 发布:法国盐之花淘宝 编辑:程序博客网 时间:2024/05/21 17:13
A - QAQ
“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!).
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.
Example
Input
QAQAQYSYIOIWIN
Output
4
Input
QAQQQZZYNOIWIN
Output
3
Note
In the first example there are 4 subsequences “QAQ”: “QAQAQYSYIOIWIN”, “QAQAQYSYIOIWIN”, “QAQAQYSYIOIWIN”, “QAQAQYSYIOIWIN”.
//水题#include <iostream>#include <cstring>using namespace std;int main(){ string s;int m[120]; memset(m,0,sizeof(m)); getline(cin,s);int k=0; for(int i=0;i<s.size();i++) { m[i]=k; if(s[i]=='Q') k++; //cout<<m[i]<<" "; } m[s.size()]=k; //cout<<endl; int ans=0; for(int i=0;i<s.size();i++) { if(s[i]=='A'){ //cout<<i<<endl; ans+=m[i]*(m[s.size()]-m[i]); //cout<<m[i]<<" "<<m[s.size()]<<endl; } } cout<<ans<<endl; return 0;}
- codeforces 894 A题 QAQ -mystical_curve
- codeforces 894A. QAQ
- Codeforces Round #447 A. QAQ
- A. QAQ
- Codeforces Round #447 (Div. 2) A. QAQ 暴力
- Codeforce 894A QAQ(计数)
- Codeforces Round#447 Div2 QAQ
- QAQ
- QAQ
- CodeForces 606B Testing Robots【读题题QAQ】
- 上午的计数题QAQ
- QAQ & ORZ 的签到题
- QAQ & ORZ 的签到题
- QAQ & ORZ 的签到题
- QAQ & ORZ 的签到题
- QAQ & ORZ 的签到题
- codeforces 894-A
- codeforces 894A
- web项目报Cannot create PoolableConnectionFactory(违反约束)错误
- 行走在OI路上
- tensorflow object detection api训练自己的数据集
- 20171120WindowsPrj09_01Socket
- IDEA中Git的更新、提交、还原方法
- codeforces 894 A题 QAQ -mystical_curve
- WKWebView遇上UIScrollView,动态获取WKWebView的高度
- Python基础入门之函数二
- mysql 操作数据
- 数列求和-加强版(20 分) 给定某数字A(1≤A≤9)以及非负整数N(0≤N≤100000),求数列之和S=A+AA+AAA+⋯+AA⋯A(N个A)。例如A=1, N=3时,S=1+11+111=
- Spring 源码解析之HandlerAdapter源码解析(三)
- java 单列集合list及其子实现类
- @SessionAttributes(value="user")
- c++ 抽象基类、虚函数、纯虚函数 java抽象类、接口、android生命周期方法异同