Skip to content

Adding Abhishek.java File #8

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
50 changes: 50 additions & 0 deletions pattern2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please import specific classes instead of import the whole package.

import java.util.regex.*;
import java.io.*;

class pattern
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please properly format your code, indentation is not correct.

public static void main(String args[])
{

Scanner sc=new Scanner(System.in);
String s=sc.nextLine();

int n=sc.nextInt();
sc.nextLine();
String arr[]=new String[n];
int arr2[]=new int[100];


for(int i=0;i<n;i++)
{

arr[i]=sc.nextLine();
}

int k=0,count=0;
for(int i=0;i<n;i++){
Copy link
Contributor

Choose a reason for hiding this comment

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

create a separate method to get the output.

Pattern p1=Pattern.compile(arr[i]);
Matcher m = p1.matcher(s);
Copy link
Contributor

Choose a reason for hiding this comment

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

please give some meaningful names to variables. p1, m doesn't make any sense.

while(m.find())
{
arr2[k++]=m.start();

count++;
}
}

Arrays.sort(arr2);

for(int i=arr2.length-count;i<arr2.length;i++)
{
System.out.print(""+arr2[i]+"\t");
}

}
}