include iostream include string int main std string str TFFTFFT int co

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