Skip to content

Adding aadarshmishra.java file. #5

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 1 commit 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
27 changes: 27 additions & 0 deletions aadarshmishra.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AndroidWorkDay1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filename & class name should be same.

{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
String text = s.nextLine();
int n = s.nextInt();
s.nextLine();
List<Integer> ans = new ArrayList<Integer>();
while(n-- > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use separate method to get the output.

String pat = s.nextLine();
Pattern pattern = Pattern.compile(pat);
Matcher m = pattern.matcher(text);
while (m.find()) {
ans.add(m.start());
}
}
Collections.sort(ans);
for(int i=0 ; i < ans.size() ; i++) {
System.out.print(ans.get(i) + " ");
}
}
}