include iostream include vector include string include algorithm int m

 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 <vector>
#include <string>
#include <algorithm>
int main() {
std::string str("TFFTFFT");
std::vector<int> resultF;
std::vector<int> resultT;
int countT =0;
int countF =0;
for(int i=0; i!=str.length(); i++) {
if(str[i] == 'T') {
countT++;
countF = 0;
} else if (str[i] == 'F') {
countF++;
countT = 0;
}
resultF.push_back(countF);
resultT.push_back(countT);
}
std::sort(resultT.begin(), resultT.end());
std::sort(resultF.begin(), resultF.end());
std::cout<<((resultF[resultF.size()-1]<resultT[resultT.size()-1])? resultT[resultT.size()-1]:resultF[resultF.size()-1]);
std::cout<<((resultF[resultF.size()-1]<resultT[resultT.size()-1])? 'T':'F');
return 0;
}