A. QAQ
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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!).

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
Note

In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".

题目大意:找字符串QAQ出现的次数.

分析:题目数据范围不大,三种暴力循环就可以过,事实上有O(n)的写法,设f[i][1/2/3]分别为前i位匹配了1/2/3位的方案数,对于每一位判断一下是否等于Q或A,非常简单地转移一下就好了.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <algorithm> using namespace std; char s[];
int f[][], len; int main()
{
scanf("%s", s + );
len = strlen(s + );
for (int i = ; i <= len; i++)
{
f[i][] = f[i - ][];
f[i][] = f[i - ][];
f[i][] = f[i - ][];
if (s[i] == 'Q')
{
f[i][]++;
f[i][] += f[i - ][];
}
if (s[i] == 'A')
f[i][] += f[i - ][];
}
printf("%d\n", f[len][]);
return ;
}

Codeforces 894.A QAQ的更多相关文章

  1. [codeforces 894 E] Ralph and Mushrooms 解题报告 (SCC+拓扑排序+DP)

    题目链接:http://codeforces.com/problemset/problem/894/E 题目大意: $n$个点$m$条边的有向图,每条边有一个权值,可以重复走. 第$i$次走过某条边权 ...

  2. codeforces #447 894A QAQ 894B Ralph And His Magic Field 894C Marco and GCD Sequence

    A.QAQ 题目大意:从给定的字符串中找出QAQ的个数,三个字母的位置可以不连续 思路:暴力求解,先找到A的位置,往前扫,往后扫寻找Q的个数q1,q2,然 后相乘得到q1*q2,这就是这个A能够找到的 ...

  3. Codeforces 894.E Ralph and Mushrooms

    E. Ralph and Mushrooms time limit per test 2.5 seconds memory limit per test 512 megabytes input sta ...

  4. Codeforces 894.C Marco and GCD Sequence

    C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input sta ...

  5. Codeforces 894.D Ralph And His Tour in Binary Country

    D. Ralph And His Tour in Binary Country time limit per test 2.5 seconds memory limit per test 512 me ...

  6. Codeforces 894.B Ralph And His Magic Field

    B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input ...

  7. Codeforces Round #447 (Div. 2) A. QAQ【三重暴力枚举】

    A. QAQ time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  8. Codeforces Round #442 (Div. 2) B题【一道模拟题QAQ】

    B. Nikita and string One day Nikita found the string containing letters "a" and "b&qu ...

  9. 【Codeforces Round #447 (Div. 2) A】QAQ

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] C语言程序练习题 [代码] #include <bits/stdc++.h> using namespace std; ...

随机推荐

  1. php 小坑记录

    1 empty  PHP<=5.5不能用于判断一个表达式的执行结果并且netbeans 和eclipse编辑器识别不出来此错误 含有此用法的 类 和页面将会报错 empty($this-> ...

  2. 文本编辑器vim/vi用法完全解读

    vi用法 1.启动vim 2.命令模式和输入模式 3.退出vi 4.vi与ex命令 5.移动光标 6.跳转 7.搜索 8.插入文本 9.修改文本 10.替换文本 11.删除文本 12.恢复和撤销改变 ...

  3. WPF中给Button加上图标和文字

    要实现在Button里面加入图标或者图形以及文字,我们就需要在Button里面用一个WrapPanel控件,这个WrapPanel控件会把我们的图标或者文字进行包裹,并显示出来. Xaml: < ...

  4. c语言实验7 文件

    part 1 验证性实验 验证性实验1 验证性实验2:已知文本数据文件file1.dat,从中读取数据,找出最高分和最低分学生信息,并输入在屏幕上. 运行结果如下图: #include <std ...

  5. shell脚本自动部署及监控

    一.shell脚本部署nginx反向代理和三个web服务 1 对反向代理服务器进行配置 #!/bin/bash #修改用户交互页面 用户输入参数执行相应的参数 #安装epel扩展包和nginx fun ...

  6. oracle调用子存储过程+游标循环实例

    一,有子节点的部门的子节点的排序,调用子存储过程 CREATE OR REPLACE PROCEDURE "PRO_INIT_SORT" AS CURSOR cur_departm ...

  7. Shell脚本调用Oralce数据库SQL文生产日志

    #!/bin/shexport LANG="zh.CN.GBK" echo -n "******************************************* ...

  8. ios之UIScrollView

    UIScrollView 类负责所有基于 UIKit 的滚动操作. 一.创建 [java] view plaincopy     CGRect bounds = [ [ UIScreen mainSc ...

  9. CF-1110 (2019/02/08)

    CF-1110 A. Parity 快速幂的思想,考虑最后一位即可 #include <bits/stdc++.h> using namespace std; typedef long l ...

  10. bzoj5469 [FJOI2018]领导集团问题

    题目描述: bz luogu 题解: 相当于树上$LIS$问题. 考虑一维情况下的贪心,我们可以用multiset启发式合并搞. 代码: #include<set> #include< ...