bug:遇到字符0时,需要重置cnt
#include<iostream>
using namespace std;
int main(){
int n;
string str;
cin>>n;
while(n--){
cin>>str;
string res;
int cnt = 0;//记录连续1的个数
int len = str.size();
for(int i = 0;i < len;i++){
if(str[i] == '1'){
cnt++;//每遇到一个1,cnt++
res += str[i];
if(cnt == 5){
i++;//跳过下一个0
cnt = 0;//重置cnt
}
}else{
cnt = 0;//如果当前为'0',则要重置cnt
res += str[i];
}
}
cout<<res<<endl;
}
return 0;
}