标签:sicily
Time Limit: 1 secs, Memory Limit: 256 MB
The first line of input contains a single integer P, (1P1000), 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.
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.
4 1 HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH 2 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 3 HHTTTHHTTTHTHHTHHTTHTTTHHHTHTTHTTHTTTHTH 4 HTHTHHHTHHHTHTHHHHTTTHTTTTTHHTTTTHTHHHHT
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
每周一赛第一场
#include <stdio.h> #include <algorithm> #include <string.h> using namespace std; int main() { int hhtt[8], temp, i, case_num; char ht[55]; scanf("%d", &case_num); while (case_num--) { memset(hhtt, 0, sizeof(hhtt)); memset(ht, '\0', sizeof(ht)); scanf("%d", &temp); scanf("%s", ht); for (i = 0; i < (int)strlen(ht) - 2; i++) { if (ht[i] == 'T' && ht[i + 1] == 'T' && ht[i + 2] == 'T') hhtt[0]++; else if (ht[i] == 'T' && ht[i + 1] == 'T' && ht[i + 2] == 'H') hhtt[1]++; else if (ht[i] == 'T' && ht[i + 2] == 'T' && ht[i + 1] == 'H') hhtt[2]++; else if (ht[i] == 'T' && ht[i + 1] == 'H' && ht[i + 2] == 'H') hhtt[3]++; else if (ht[i] == 'H' && ht[i + 1] == 'T' && ht[i + 2] == 'T') hhtt[4]++; else if (ht[i] == 'H' && ht[i + 2] == 'H' && ht[i + 1] == 'T') hhtt[5]++; else if (ht[i] == 'H' && ht[i + 1] == 'H' && ht[i + 2] == 'T') hhtt[6]++; else hhtt[7]++; } printf("%d", temp); for (int i = 0; i < 8; i++) { printf(" %d", hhtt[i]); } printf("\n"); } return 0; }
标签:sicily
原文地址:http://blog.csdn.net/u012925008/article/details/44739645