Skip to content

Adding Harshit_Maharshi.java file #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Harshit_Maharshi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
class Harshit_Maharshi {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//Reading the text
String text = br.readLine();
int n = Integer.parseInt(br.readLine());
String[] patterns = new String[n];
//Reading patterns
for(int i=0;i<n;i++)
patterns[i] = br.readLine();
//Function to get index for the patterns in the text
getIndex(text, patterns);
}

static void getIndex(String t1, String[] pat) {
int[] j = new int[pat.length];
Arrays.fill(j,-1);
int ch;
for(int i=0;i<pat.length;) {
ch = 0;
while((j[i]=t1.indexOf(pat[i], j[i]+1)) != -1) {
System.out.print(j[i]+" ");
ch = 1;
i++;
break;
}
i=i==pat.length?0:i;
if(ch==0)
break;
}
}
}