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. IOS之UI异步刷新

    NSOperationQueue     *operationQueue; // for rendering pages on second thread [operationQueue waitUn ...

  2. 通过 Azure IoT 中心实现互联网设备数据的可视化分析

    本课程主要介绍了如何 在Azure 平台上借助 Azure IoT 中心, Azure 流分析,Web 应用, Azure 数据库等服务快速构建收集处理并可视化来自设备的数据流的应用, 包括项目背景介 ...

  3. SAP C/4HANA到底包含哪些产品?

    2018年6月的SAPPHIRE(蓝宝石大会)上, SAP发布了新的商务软件套件:C/4HANA,意在通过SAP C/4HANA将前台应用和SAP Digital Core(数字化核心)S/4HANA ...

  4. ImportError: No module named flask.ext.wtf 解决方法

    install pip install flask.ext.wtf

  5. javaEE(7)_自定义标签&JSTL标签(JSP Standard Tag Library)

    一.自定义标签简介 1.自定义标签主要用于移除Jsp页面中的java代码,jsp禁止出现一行java脚本. 2.使用自定义标签移除jsp页面中的java代码,只需要完成以下两个步骤: •编写一个实现T ...

  6. c++ 读取一行的2个数

    #include <iostream> using namespace std; double harmonicMean(double x, double y); int main() { ...

  7. mysql:10道mysql查询语句面试题

    表结构 学生表student(id,name) 课程表course(id,name) 学生课程表student_course(sid,cid,score) 创建表的sql代码 ```sql creat ...

  8. Python Third Day-函数

    ''' 为什么要有函数?没有函数带来的困扰? 组织结构不清晰,可读性差 代码冗余 可扩展性差 什么是函数 具备某一个功能的工具--->函数 事先准备工具->函数的定义 拿来就用.重复使用- ...

  9. Vuex 实际使用中的一点心得 —— 一刷新就没了

    问题 在开发中,有一些全局数据,比如用户数据,系统数据等.这些数据很多组件中都会使用,我们当然可以每次使用的时候都去请求,但是出于程序员的"洁癖"."抠"等等优 ...

  10. C语言获取Shell返回结果

    Linux编程时候,如果我们需要调用shell命令或脚本通常使用system方法.如system("ls") 该方法返回值为0或-1,即成功或失败.而有的时候我们想要获取shell ...