Loại bỏ các xâu con “100” trong S

mn xem giúp e code bài này với ạ. E cảm ơn


https://paste.ofcode.org/DzGVknSr4C2bqDFB7Hhxaq

using namespace std;
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
int main()
{
    int t;cin>>t;
    while(t--)
	{
		string s;cin>>s;
		vector <pair<char,int>> v;
		v.push_back(make_pair('!',-1));
		int max1=0;
		for(int i=0;i<s.length();i++)
		{
			v.push_back(make_pair(s[i],i));
			while(v.size()>=3&&v[v.size()-3].first=='1'&&v[v.size()-2].first=='0'
			&&v[v.size()-1].first=='0')
			{
				v.pop_back();v.pop_back();v.pop_back();
			}
			max1=max(max1,i-v.back().second);
		}
		cout<<max1<<endl;
	}
}

Đúng hay sai thì bạn chạy thử thì biết chứ. :thinking:

5 Likes

e thấy chạy thì đúng nhưng submit trên mạng thì wa ạ :frowning:

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?