Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Please debug the code

Правка en1, от fakehandle, 2021-03-25 22:06:19

Hi everyone In contest This Question the solution i wrote . But now i am not able to find the logical mistake please help me to find logical mistake.

thanks in advance here is code ...

include

using namespace std;

define ll long long int

int main(){ ll t ; cin>>t; while(t--){ ll n ,k; cin>>n>>k; string s; cin>>s; ll lastX=-1,lastS=-1; ll count=0; ll last=-1,i; for(i=0;i<n;i++){ if(s[i]=='*'){ s[i]='x'; lastX=i; count++; break; } } for(i=n-1;i>=0;i--){ if(s[i]=='*'){ last=i; count++; s[i]='x'; break; } } if(last==-1 || last — lastX<=k){ cout<<count<<endl; } else{ for(i=0;i<n;i++){ if(s[i]=='*'){ if(i-lastX<k){ lastS=i; } else if((i-lastX==k)) { s[i]='x'; lastX=i; lastS=-1; count++; } else{ s[lastS]='x'; lastX=lastS; lastS=-1; count++; } } } if(last-lastX>k&&lastS!=-1){ count++; } cout<<count<<endl; } } } ...

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский fakehandle 2021-03-25 22:07:11 23
en1 Английский fakehandle 2021-03-25 22:06:19 1178 Initial revision (published)