-
Notifications
You must be signed in to change notification settings - Fork 30
Adding ShivamShukla.java File #6
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import java.io.*; | ||
|
||
import java.util.*; | ||
|
||
import java.util.regex.*; | ||
|
||
class Shivam | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do proper formatting in your code & import specific classes instead of import the whole package. |
||
public static void main(String args[]) | ||
|
||
{ Scanner sc=new Scanner(System.in); | ||
|
||
int n; | ||
|
||
String text=sc.nextLine(); | ||
|
||
n=Integer.parseInt(sc.nextLine()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use sc.nextInt() instead of Integer.parseInt(sc.nextLine()); |
||
|
||
pass(text,n); | ||
|
||
} | ||
|
||
public static void pass(String t,int n) | ||
|
||
{ | ||
String temp=t; | ||
Scanner sc=new Scanner(System.in); | ||
int i; | ||
String a[]=new String[100]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid static allocation. if n is 5 then the rest of the memory will be wasted. if n will go more than 100 it will throw IndexOutOfBoundException. |
||
|
||
ArrayList<Integer>res = new ArrayList<>(); | ||
|
||
for(i=0;i<n;i++) | ||
|
||
{ | ||
a[i]=sc.nextLine(); | ||
|
||
} | ||
|
||
for(i=0;i<n;i++) | ||
|
||
{ | ||
for(int j=-1;(j=temp.indexOf(a[i],j+1)) !=-1;) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try not to use predefined methods like indexOf(). Instead you can iterate the input and match characters. |
||
|
||
{ | ||
res.add(j); | ||
|
||
} | ||
|
||
} | ||
|
||
Collections.sort(res); | ||
|
||
for(Integer k:res) | ||
System.out.print(k+" "); | ||
|
||
} | ||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improper indentation. Please correct