Skip to content

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

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
59 changes: 59 additions & 0 deletions ShivamShukla.java
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
Copy link

@olleh423 olleh423 Aug 18, 2018

Choose a reason for hiding this comment

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

Improper indentation. Please correct

{
Copy link
Contributor

Choose a reason for hiding this comment

The 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());

Choose a reason for hiding this comment

The 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];

Choose a reason for hiding this comment

The 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;)

Choose a reason for hiding this comment

The 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+" ");

}

}