fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. void solve(){
  6. int n;
  7. cin >> n;
  8. int k;
  9. cin >> k;
  10.  
  11. string s;
  12. cin >> s;
  13.  
  14. int begin = 0;
  15. int end = 0;
  16.  
  17. for (int i = 0; i < n; i++){
  18. if (s[i] == '*'){
  19. s[i] = 'x';
  20. begin = i;
  21. break;
  22. }
  23. }
  24.  
  25. for (int i = n-1; i >= 0; i--){
  26. if (s[i] == '*'){
  27. s[i] = 'x';
  28. end = i;
  29. break;
  30. }
  31. }
  32.  
  33. while (begin < end){
  34. if (s[begin] == 'x'){
  35. begin = min(end, begin + k);
  36. }
  37. else if (s[begin] =='.'){
  38. begin--;
  39. }
  40. else s[begin] = 'x';
  41. }
  42.  
  43. int sum = 0;
  44.  
  45. for (int i = 0; i < n; i++){
  46. if (s[i] == 'x') sum++;
  47. }
  48.  
  49. cout << sum << '\n';
  50. }
  51.  
  52.  
  53. int main(){
  54. int tc; cin >> tc; while(tc--)solve();
  55. }
Success #stdin #stdout 0s 5324KB
stdin
5
7 3
.**.***
5 1
..*..
5 2
*.*.*
3 2
*.*
1 1
*
stdout
3
1
3
2
1