bholuakku's blog

By bholuakku, history, 6 years ago, In English

Can someone please tell me what is wrong in my code. Thanks in advance.

This is the link of the problem.

This is my solution code.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I used bruteforce))

#include<bits/stdc++.h>
using namespace std;
int clears(string s,string p){
	int n=p.size();
	for(int i=s.find(p);i!=string::npos;i=s.find(p))
		s.erase(i,n);
	return s.size();
}
signed main(){
	int test;
	cin>>test;
	string line;
	bool flag=0;
	while(test--){
	        cin>>line;
		bool flag1=0;
		if(flag1)
		    cout<<'\n';
		flag=1;
		for(int i=1;i<line.size();i++){
			if(clears(line,line.substr(0,i))==0){
				cout<<i<<'\n'; 
				flag1=1;
				break;
			}
		}
		if(!flag1)
		    cout<<line.size()<<'\n';
	}
}