1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
# include<iostream>
# include <cmath>
# include <algorithm>
# include <string>
# include <stdio.h>
using namespace std;
int main()
{
int TTT=0,TTH=0,THT=0,THH=0,HTT=0,HTH=0,HHT=0,HHH=0;
string str;
string a1="TTT",a2="TTH",a3="THT",a4="THH",a5="HTT",a6="HTH",a7="HHT",a8="HHH";
int t,n,j;
cin>>t;
for (int i=0;i<t;i++)
{
TTT=0;TTH=0;THT=0;THH=0;HTT=0;HTH=0;HHT=0;HHH=0;
cin>>n>>str;
j=str.length()-3;
for (int x=1;x<j;i++)
{
if (str.substr(i,3)==a1)
TTT++;
else if (str.substr(i,3)==a2)
TTH++;
else if (str.substr(i,3)==a3)
THT++;
else if (str.substr(i,3)==a4)
THH++;
else if (str.substr(i,3)==a5)
HTT++;
else if (str.substr(i,3)==a6)
HTH++;
else if (str.substr(i,3)==a7)
HHT++;
else if (str.substr(i,3)==a8)
HHH++;
}
cout<<n<<" "<<TTT<<" "<<THT<<" "<<THH<<" "<<HTT<<" "<<HTH<<" "<<HHT<<" "<<HHH<<endl;
}
}
|