include iostream include string int main std string str TFFTTT if str

 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
#include <iostream>
#include <string>
int main() {
std::string str("TFFTTT");
if(str[str.length() -1] == 'T') {
str.push_back('F');
} else if (str[str.length()-1] == 'F') {
str.push_back('T');
}
int countT = 0;
int countF = 0;
int reF = 0;
int reT = 0;
for(int i=0; i!=str.length(); i++) {
if(str[i] == 'T') {
countT++;
if(countF > 1) {
reF++;
}
countF = 0;
} else if (str[i] == 'F') {
countF++;
if(countT > 1) {
reT++;
}
countT = 0;
}
}
std::cout<<reF<<"F"<<reT<<"T";
return 0;
}