59 lines
1.2 KiB
C++
Executable File
59 lines
1.2 KiB
C++
Executable File
#include <iostream>
|
|
#include <string>
|
|
#include <ranges>
|
|
#include <vector>
|
|
|
|
using std::cin, std::cout, std::string, std::vector, std::iostream;
|
|
constexpr auto range = std::ranges::views::iota;
|
|
|
|
size_t n;
|
|
string s;
|
|
int a_num, b_num;
|
|
char max_char, min_char;
|
|
|
|
struct Ope{
|
|
const size_t start,end;
|
|
const char c;
|
|
};
|
|
vector<Ope> v;
|
|
|
|
void print()noexcept{
|
|
cout<<v.size()<<'\n';
|
|
for(auto &i:v){
|
|
cout<<i.start+1<<' '<<i.end+1<<' '<<i.c<<'\n';
|
|
}
|
|
}
|
|
|
|
int main(){
|
|
iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);
|
|
cin>>n;
|
|
cin>>s;
|
|
for(const int i:range((size_t)0,n)){
|
|
if(s[i]=='A') {
|
|
a_num++;
|
|
}else if(s[i]=='B'){
|
|
b_num++;
|
|
}
|
|
}
|
|
if(a_num>=b_num){
|
|
max_char = 'A';
|
|
min_char = 'B';
|
|
}else{
|
|
max_char = 'B';
|
|
min_char = 'A';
|
|
}
|
|
v.push_back({0,(size_t)n-1,max_char});
|
|
for(size_t i=0;i<n;i++){
|
|
if(s[i]==min_char){
|
|
size_t end {i};
|
|
for(size_t j=i+1;j<n;j++){
|
|
if(s[j]!=min_char)break;
|
|
end=j;
|
|
}
|
|
v.push_back({i,end,min_char});
|
|
i=end+1;
|
|
}
|
|
}
|
|
|
|
print();
|
|
} |