Codeforces Round #447 (Div. 2) A. QAQ【三重暴力枚举】
1 second
256 megabytes
standard input
standard 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!).

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.
The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
QAQAQYSYIOIWIN
4
QAQQQZZYNOIWIN
3
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
【题意】:含QAQ的序列有多少(不要求连续)。
【分析】:三重循环枚举。
【代码】:
#include <bits/stdc++.h> using namespace std; const int maxn = ;
int main()
{
char a[maxn];
int ans;
gets(a+);//注意+1!因为从1开始!!!
int n=strlen(a+);
ans=;
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
for(int k=j+;k<=n;k++)
{
if(a[i]=='Q'&&a[j]=='A'&&a[k]=='Q')
{
ans++;
}
}
}
}
printf("%d\n",ans);
return ;
}
枚举
Codeforces Round #447 (Div. 2) A. QAQ【三重暴力枚举】的更多相关文章
- Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)
题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...
- Codeforces Round #349 (Div. 1) B. World Tour 暴力最短路
B. World Tour 题目连接: http://www.codeforces.com/contest/666/problem/B Description A famous sculptor Ci ...
- Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分
D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...
- 【Codeforces Round #447 (Div. 2) A】QAQ
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] C语言程序练习题 [代码] #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #447 (Div. 2) 题解 【ABCDE】
BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imag ...
- Codeforces Round #447 (Div. 2)
我感觉这场CF还是比较毒的,虽然我上分了... Problem A QAQ 题目大意:给你一个由小写字母构成的字符串,问你里面有多少个QAQ. 思路:找字符串中的A然后找两边的Q即可,可以枚举找Q, ...
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field 数学
题目链接 题意:给你三个数n,m,k;让你构造出一个nm的矩阵,矩阵元素只有两个值(1,-1),且满足每行每列的乘积为k,问你多少个矩阵. 解法:首先,如果n,m奇偶不同,且k=-1时,必然无解: 设 ...
- Codeforces Round #447 (Div. 2) 题解
A.很水的题目,3个for循环就可以了 #include <iostream> #include <cstdio> #include <cstring> using ...
- Codeforces Round #447 (Div. 2) C 构造
现在有一个长度为n的数列 n不超过4000 求出它的gcd生成set 生成方式是对<i,j> insert进去(a[i] ^ a[i+1] ... ^a[j]) i<=j 然而现在给 ...
随机推荐
- 《Cracking the Coding Interview》——第11章:排序和搜索——题目8
2014-03-21 22:23 题目:假设你一开始有一个空数组,你在读入一些整数并将其插入到数组中,保证插入之后数组一直按升序排列.在读入的过程中,你还可以进行一种操作:查询某个值val是否存在于数 ...
- 《Cracking the Coding Interview》——第6章:智力题——题目3
2014-03-20 00:48 题目:有3升的瓶子和5升的瓶子,只允许倒满.倒到满为止.或是泼光三种操作,怎么搞出4升水呢? 解法:如果A和B是互质的两个正整数,且A<B,令X=B-A,则(X ...
- 《Cracking the Coding Interview》——第4章:树和图——题目5
2014-03-19 04:11 题目:设计算法检查一棵二叉树是否为二叉搜索树. 解法:既然是二叉搜索树,也就是说左子树所有节点都小于根,右子树所有节点都大于根.如果你真的全都检查的话,那就做了很多重 ...
- Python3中文教程
搜索 此文档来源自网络 安装 PYTHON❝ Tempora mutantur nos et mutamur in illis. (时光流转,吾等亦随之而变.) ❞ — 古罗马谚语 深入欢迎来到 Py ...
- USACO Section2.2 Runaround Numbers 解题报告 【icedream61】
runround解题报告---------------------------------------------------------------------------------------- ...
- 4.实现简单的shell sed替换功能
# -*- coding:utf-8 -*- # Author: JACK ZHAO # 程序1: 实现简单的shell sed替换功能 import sys #判断参数个数 if len(sys.a ...
- (原)Unreal 渲染模块引言Temp
@author:白袍小道 引言 本文只在对Unreal渲染模块做一些详细的理解,务求能分析出个大概. 其中框架的思想和实现的过程,是非常值得学习和推敲一二的. 涉及资源系统,材 ...
- 多线程和CPU的关系
什么是CPU (1) Central Progressing Unit 中央处理器,是一块超大规模的集成电路,是一台计算机的运算核心和控制核心. (2) CPU包括 ...
- SheetJS & Error: Sheet names cannot exceed 31 chars
SheetJS Error: Sheet names cannot exceed 31 chars title + version https://github.com/SheetJS/js-xlsx ...
- resultMap与resultType的区别等容易混淆的概念
都是为了表示结果集与java对象的关系 resultType只能通过属性与列的名称进行对应,并且大小写不敏感 resultType也可以是map(这样写会大小写敏感),不是自定义类型也行 result ...