题目链接:http://acm.swust.edu.cn/problem/795/

Time limit(ms): 1000        Memory limit(kb): 65535
 
Description

Penney’s game is a simple game typically played by two players. One version of the game calls for each player to choose a unique three-coin sequence such as HEADS TAILS HEADS (HTH). A fair coin is tossed sequentially some number of times until one of the two sequences appears. The player who chose the first sequence to appear wins the game.

For this problem, you will write a program that implements a variation on the Penney Game. You will read a sequence of 40 coin tosses and determine how many times each three-coin sequence appears. Obviously there are eight such three-coin sequences: TTT, TTH, THT, THH, HTT, HTH, HHT and HHH. Sequences may overlap. For example, if all 40 coin tosses are heads, then the sequence HHH appears 38 times.

Input

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set consists of 2 lines. The first line contains the data set number N. The second line contains the sequence of 40 coin tosses. Each toss is represented as an upper case H or an upper case T, for heads or tails, respectively. There will be no spaces on any input line.

 
Output

For each data set there is one line of output. It contains the data set number followed by a single space, followed by the number of occurrences of each three-coin sequence, in the order shown above, with a space between each one. There should be a total of 9 space separated decimal integers on each output line.

Sample Input

 
4
1
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
2
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
3
HHTTTHHTTTHTHHTHHTTHTTTHHHTHTTHTTHTTTHTH
4
HTHTHHHTHHHTHTHHHHTTTHTTTTTHHTTTTHTHHHHT
Sample Output
1 0 0 0 0 0 0 0 38
2 38 0 0 0 0 0 0 0
3 4 7 6 4 7 4 5 1
4 6 3 4 5 3 6 5 6
 
题目大意:可以理解为抛硬币游戏,HT代表正反面,这里选取3次结果为一组分别按照这个顺序TTT, TTH, THT, THH, HTT, HTH, HHT, HHH. 
     下面输入一个数n,代表测试数据的组数,然后每一组一个40个字符的字符串,输出上面对应的每一种排列的次数,输出的第一个数代表组号
 
懂了意思都好说,直接上代码:
 #include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
string x, s[] = { "TTT", "TTH", "THT", "THH", "HTT", "HTH", "HHT", "HHH" };
int t, n, cnt[];
int main(){
cin >> t;
while (t--){
memset(cnt, , sizeof(cnt));
cin >> n >> x;
for (int i = , len = x.size(); i < ; i++){
int pos = -;
while (){
pos = x.find(s[i].c_str(), pos + );
if (pos == string::npos) break;//npos代表一个不存在的量
cnt[i]++;
}
}
cout << n;
for (int i = ; i < ; i++) cout << ' ' << cnt[i];
cout << endl;
}
return ;
}

[Swust OJ 795]--Penney Game的更多相关文章

  1. [Swust OJ 404]--最小代价树(动态规划)

    题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535   Des ...

  2. [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)

    题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...

  3. SWUST OJ NBA Finals(0649)

    NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128   Descri ...

  4. [Swust OJ 1023]--Escape(带点其他状态的BFS)

    解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535     Descript ...

  5. [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)

    题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  6. [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)

    题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...

  7. [Swust OJ 1026]--Egg pain's hzf

      题目链接:http://acm.swust.edu.cn/problem/1026/     Time limit(ms): 3000 Memory limit(kb): 65535   hzf ...

  8. [Swust OJ 1139]--Coin-row problem

    题目链接:  http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...

  9. [Swust OJ 385]--自动写诗

    题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535    Descripti ...

随机推荐

  1. IOS 特定于设备的开发:获取额外的设备信息

    sysctl()和sysctlbyname()允许获取系统信息.这些标准的UNIX函数用于询问操作系统有关硬件和OS的详细信息. 这些常量使你能够检查核心信息,比如系统的CPU频率,可用的内存量等.它 ...

  2. 一些特殊css

    属性 描述            outline  (轮廓)是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用. outline:#00FF00 dotted thick; 可以按顺序 ...

  3. Mac使用技巧

    外接显示器的生活,在 系统偏好设置--显示器--排列中,点击那个白色的条,可以设置主显示器.

  4. SSD的来由与优势

           SSD,对于很多人来说,它现在已不再是个很陌生的名词,有些网友谐趣的把它称作“湿湿的”,这里既有谐音的意味,也有称赞SSD意思.虽然大家对SSD已不算陌生,但恐怕对SSD的历史也所知不多 ...

  5. linux下解压iso文件

    .iso文件的格式是iso9660,iso9660是cd上的一种文件系统, 也就是说是 是数据在cd上的组织形式: 它的一些限制是: 1.最多8级子目录(可以用RockRidge Extension增 ...

  6. 使用资源监控工具 glances

    http://www.ibm.com/developerworks/cn/linux/1304_caoyq_glances/ glances 可以为 Unix 和 Linux 性能专家提供监视和分析性 ...

  7. 拥抱开源,怎样关注Linux Kernel 邮件列表?

    现在开源如此火爆.以至于张口闭口不提到都仿佛不是搞IT 的.那么怎样拥抱开源?本文适合刚開始学习的人,如有大神至此,goto exit ! 一.怎样增加开源 以Linux 为例,这么一个成功的开源项目 ...

  8. Visual format language

    所谓的VFL语言其实就是Visual format language 的缩写,是一种使用代码添加约束的方式,类似于Masonry  SDAutolayout的效果,但是操作起来可能要相对简单.一行代码 ...

  9. Unity Editor下对资源进行操作时调用AssetModificationProcessor

    public class Test : UnityEditor.AssetModificationProcessor { private static void OnWillCreateAsset(s ...

  10. js页面跳转 和 js打开新窗口 方法

    js页面跳转 和 js打开新窗口 方法 第一种: 第二种: 第三种: 第四种: 第五种: 1.在原来的窗体中直接跳转用 window.location.href="你所要跳转的页面" ...