[Swust OJ 795]--Penney Game

时间:2022-09-20 15:50:43

题目链接: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. &lbrack;Swust OJ 404&rsqb;--最小代价树&lpar;动态规划&rpar;

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

  2. &lbrack;Swust OJ 649&rsqb;--NBA Finals&lpar;dp&comma;后台略&lpar;hen&rpar;坑&rpar;

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

  3. SWUST OJ NBA Finals&lpar;0649&rpar;

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

  4. &lbrack;Swust OJ 1023&rsqb;--Escape&lpar;带点其他状态的BFS&rpar;

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

  5. &lbrack;Swust OJ 1125&rsqb;--又见GCD&lpar;数论,素数表存贮因子&rpar;

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

  6. &lbrack;Swust OJ 1126&rsqb;--神奇的矩阵&lpar;BFS&comma;预处理&comma;打表&rpar;

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

  7. &lbrack;Swust OJ 1026&rsqb;--Egg pain&&num;39&semi;s hzf

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

  8. &lbrack;Swust OJ 1139&rsqb;--Coin-row problem

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

  9. &lbrack;Swust OJ 385&rsqb;--自动写诗

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

随机推荐

  1. vscode常用设置

    1.代码提示快捷键设置:(keybindings.json) { "key": "ctrl+j","command": "edit ...

  2. AFnetworking3&period;1的基本使用

    听说之后AFHttpWorking版本可能会影响到苹果的审核,今天下了最新版本的AFHttpWorking,并且做了简单的封装,我这里是通过cocoapods下载了两个工具 1=AFHttpWorki ...

  3. 利用moment为基础&comma;基于DOM实现一个多个倒计时同时进行的js库方便使用

    moment非常强大,提供了很多时间方法的封装,项目需要一个小倒计时的功能,网上找了很多不合适,决定自己写一个,直接上代码 //定义一个立即执行的函数(function () { var Ticts= ...

  4. OOA、OOD、OOP分别是什么?

    什么是面向对象分析(OOA)? "面向对象分析是一种分析方法,这种方法利用从问题域的词汇表中找到的类和对象来分析需求." 什么是面向对象设计(OOD)? "面向对象设计是 ...

  5. configure - 源代码安装的第一步

    configure是源代码安装的第一步,主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系 configure有许多参数可配,具体参见./configure --help ...

  6. fiddler学习总结--Web端抓包

    步骤一: Fiddler的基本配置:Tools-->option-->Connections: 就可以进行抓包了 步骤二: 可以通过一些设置过滤: 步骤三: 抓取HTTPS的请求:1.安装 ...

  7. php运行代码流程和性能优化方法

    ---恢复内容开始--- php文件->扫描->zd引擎去理解->opcodes->执行->输出 例子,用white随机循环20000数据进行性能测试,分别对比isset ...

  8. Java 遍历类中的属性

    public static void testReflect(Object model) throws NoSuchMethodException, IllegalAccessException, I ...

  9. 公网用户接入NAT后面的freeswitch配置

    大致网络示意和终端号码: 客户端侧: 终端号码(1019)终端IP(192.168.1.15)+ 网关(192.168.1.1) + 路由器公网IP(动态地址) 服务器侧: 防火墙(181.92.2. ...

  10. 设计资源:三个精美APP原型例子下载

    原型设计是整个产品生产过程中不可或缺的一环,无论你是移动端UI设计师或是网页设计师,原型设计都会让整个设计过程更加轻松.原型是产品概念的具象化,它让每个项目参与者都能查看并提出意见以便在产品发布前日臻 ...