View Code of Problem 3832

#include<bits/stdc++.h>
using namespace std;

int main() {
	char ch1[100000],ch2[100000];
	while(cin>>ch1>>ch2){
		int len1=strlen(ch1),len2=strlen(ch2);
		int flag1=1;
		for(int i=0;i<len1;i++){
			if(ch1[i]==ch2[0]){
				int flag=1;
				for(int j=1;j<len2;j++){
					if(ch1[i+j]!=ch2[j]){
						flag=0;
						break;
					}
				}
				if(flag){
					cout<<i+1<<endl;
					flag1=0;
					break;
				}
			}
		}
		if(flag1){
			cout<<-1<<endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 3832