codeforces 894A 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!).
illustration by 貓屋 https://twitter.com/nekoyaliuBort 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.
InputThe only line contains a string of length?n?(1?≤?n?≤?100). It's guaranteed that the string only contains uppercase English letters.
OutputPrint a single integer?— the number of subsequences "QAQ" in the string.
Examples input Copy QAQAQYSYIOIWIN output Copy 4 input Copy QAQQQZZYNOIWIN output Copy 3 NoteIn the first example there are?4?subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
因為n的取值比較小,直接暴力
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int inf = 0x3f3f3f3f; int main() { // freopen("shuju.txt","r",stdin);string a;cin>>a;int len=a.length();int ans=0;for(int i=0;i<len-2;i++){for(int j=i+1;j<len-1;j++){for(int k=j+1;k<len;k++){if(a[i]=='Q'&&a[j]=='A'&&a[k]=='Q')ans++;}}}cout<<ans<<endl;return 0; }總結
以上是生活随笔為你收集整理的codeforces 894A QAQ的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 符号Symbol介绍及应用
- 下一篇: 英语语法——句子成分总结