-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Milica_and_String.cpp
132 lines (122 loc) · 2.91 KB
/
A_Milica_and_String.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <bits/stdc++.h>
using namespace std;
// Shorthand notations
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef set<int> si;
typedef set<ll> sl;
typedef priority_queue<int, vector<int>, greater<int>> min_pq;
typedef priority_queue<int> max_pq;
// Macros
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(i, n) for (int i = n - 1; i >= 0; --i)
#define forit(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define forRange(i, a, b) for (int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define INF 1e9
#define MOD 1000000007
/**
* @author jossy_: YOSEPH-SHEMELES
* @brief Custom template for CP
*/
template <typename T>
void display(vector<T> &arr) {
for (auto &i : arr) cout << i << " ";
cout << endl;
}
template <typename T>
void IL(vector<T> &arr, int n) {
arr.resize(n);
for (auto &a : arr) cin >> a;
}
// sieve of eratosthenes
void sieve(bool primes[], int x)
{
primes[1] = false;
// if a number is prime mark all its multiples
// as non prime
for (int i=2; i*i <= x; i++)
{
if (primes[i] == true)
{
for (int j=2; j*j <= x; j++)
primes[i*j] = false;
}
}
}
// gcd
int gcd(int a,int b) {
if(a == 0)
return b;
return gcd(b%a,a);
}
// Main function for solving the problem
void solve() {
// Start here
int n ; int k;
cin >> n >> k;
string s;
cin >> s;
int countb = 0;
for (int i = 0;i<s.length();i++){
if (s[i] == 'B'){
countb ++;
}
}
if (countb == k){
cout << 0 <<endl;
}
else{
if (countb > k){
int ans = 0;
cout << 1 <<endl;
for (int i = 0 ; i < s.length();i++){
ans++;
if (s[i] == 'B'){
countb--;
}
if (countb == k){
break;
}
}
cout << ans << " "<<'A'<<endl;
}
else{
cout << 1 <<endl;
int ans = 0;
for (int i = 0 ; i < s.length();i++){
ans++;
if (s[i] == 'A'){
countb++;
}
if (countb == k){
break;
}
}
cout << ans << " "<<'B'<<endl;
}
}
}
int main() {
fast_io;
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}