Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void printArray(int cnt, int n, string pos[]){
- //cout << "print: "<< cnt << " n " << n << endl;
- cout << cnt << endl;
- for(int i = 0; i < n; i++){
- //cout << " i: " << i << " pos" << pos[i] << endl;
- if( pos[i].empty()){
- cout << ".";
- }else{
- cout << pos[i] ;
- }
- }
- cout << endl;
- //cout << endl << "=====end=====" << endl;
- }
- int main(){
- //ifstream fin("shuffle_bronze_dec17/2.in");
- //ifstream fin("feeding.in");
- //freopen("feeding.in", "r", stdin);
- int t ;
- cin >> t;
- //cout << t;
- int n, k;
- //cout << n << endl;
- for(int i = 0 ; i < t; i++){
- cin >> n;
- cin >> k;
- string pos[n];
- string word;
- cin >> word;
- int cnt = 0;
- for(int j = 0; j < n; j++){
- string type;
- //cin >> type;
- type = word.substr(j,1);
- int next = j + k;
- if( next >= n){
- next = n-1;
- }
- int prev = j - k;
- if(prev < 0){
- prev = 0;
- }
- int max = 0;
- bool found = false;
- for(int k = next; k >= prev; k--){
- if(pos[k] == type){
- found = true;
- break;
- }else if(pos[k].empty()){
- //cnt++;
- //pos[k] = type;
- if(max == 0){
- max = k;
- }
- //break;
- }
- }
- if(!found){
- cnt++;
- pos[max] = type;
- }
- //cnt++;
- //pos[j] = type;
- //cout << "j: " << j << " type" << type << endl;
- }
- printArray(cnt, n, pos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement