Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int t, n, k;
- string s;
- bool check()
- {
- bool check0 = false;
- bool check1 = false;
- for (int i = 0; i < n; i++)
- {
- if (s[i] == '0') check0 = true;
- if (s[i] == '1') check1 = true;
- if (check0 &&check1) return true;
- }
- return false;
- }
- void slove(char bit)
- {
- if (!check())
- {
- int index = 0;
- while (s[index] == 'a')
- {
- index++;
- }
- s[index] = 'a';
- }
- else
- {
- for (int i = 0; i < n; i++)
- {
- if (s[i] == bit) { s[i] = 'a'; break; }
- }
- }
- }
- void print()
- {
- for (int i = 0; i < n; i++)
- {
- if (s[i] != 'a') cout << s[i];
- }
- cout << endl;
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- cin >> t;
- for (int tc = 0; tc < t; tc++)
- {
- cin >> n >> k >> s;
- int N = n, cnt = 0;
- while (N != k)
- {
- if (cnt % 2 == 0) slove('1');
- else slove('0');
- cnt++; N--;
- }
- print();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement