-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import java.util.HashMap; | ||
import java.util.Scanner; | ||
|
||
public class Anagrams{ | ||
|
||
static boolean isAnagram(String a, String b) { | ||
// Complete the function | ||
if(a.length() != b.length() || a.equals("") || b.equals("")) | ||
return false; | ||
char index; | ||
int freq; | ||
HashMap<Character,Integer> letters = new HashMap<Character,Integer>(); | ||
a = a.toUpperCase(); | ||
b = b.toUpperCase(); | ||
for(int i = 0; i < a.length(); i++){ | ||
index = a.charAt(i); | ||
if(letters.containsKey(index)){ | ||
freq = letters.get(index); | ||
letters.replace(index, ++freq); | ||
} | ||
else | ||
letters.put(index,1); | ||
} | ||
for(int i = 0; i < b.length(); i++){ | ||
index = b.charAt(i); | ||
if(letters.containsKey(index)){ | ||
freq = letters.get(index); | ||
if(freq == 0) | ||
return false; | ||
letters.replace(index, --freq); | ||
} | ||
else | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Scanner scan = new Scanner(System.in); | ||
String a = scan.next(); | ||
String b = scan.next(); | ||
scan.close(); | ||
boolean ret = isAnagram(a, b); | ||
System.out.println( (ret) ? "Anagrams" : "Not Anagrams" ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import java.math.BigDecimal; | ||
import java.util.*; | ||
|
||
public class Bigdecimal{ | ||
public static void main(String []args){ | ||
//Input | ||
Scanner sc= new Scanner(System.in); | ||
int n=sc.nextInt(); | ||
String []s=new String[n+2]; | ||
for(int i=0;i<n;i++){ | ||
s[i]=sc.next(); | ||
} | ||
sc.close(); | ||
|
||
Arrays.sort(s,0,n, new Comparator<String>(){ | ||
@Override | ||
public int compare(String x, String y){ | ||
if(x == null || y == null) | ||
return 0x0; | ||
BigDecimal first = new BigDecimal(x), second = new BigDecimal(y); | ||
return second.compareTo(first); | ||
} | ||
}); | ||
|
||
//Output | ||
for(int i=0;i<n;i++){ | ||
System.out.println(s[i]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import java.util.Scanner; | ||
import java.util.regex.*; | ||
|
||
public class Pattern_syntax_checker{ | ||
public static void main(String[] args){ | ||
Scanner in = new Scanner(System.in); | ||
int testCases = Integer.parseInt(in.nextLine()); | ||
while(testCases>0){ | ||
String pattern = in.nextLine(); | ||
try{ | ||
Pattern.compile(pattern); | ||
System.out.println("Valid"); | ||
} | ||
catch(Exception e){ | ||
System.out.println("Invalid"); | ||
} | ||
testCases--; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import java.io.*; | ||
import java.math.*; | ||
import java.util.*; | ||
|
||
public class Primality_test{ | ||
public static void main(String[] args) throws IOException{ | ||
Scanner in = new Scanner(System.in); | ||
try{ | ||
BigInteger n = in.nextBigInteger(); | ||
System.out.println(n.isProbablePrime(32) ? "prime" : "not prime"); // 1 - 1/2^32 | ||
} | ||
catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.util.Scanner; | ||
|
||
public class String_compare{ | ||
|
||
public static String getSmallestAndLargest(String s, int k) { | ||
String smallest = ""; | ||
String largest = ""; | ||
|
||
// Complete the function | ||
// 'smallest' must be the lexicographically smallest substring of length 'k' | ||
// 'largest' must be the lexicographically largest substring of length 'k' | ||
smallest = s.substring(0, k); | ||
largest = s.substring(0, k); | ||
for(int i = 1; i <= s.length()-k; i++){ | ||
if(largest.compareTo(s.substring(i, k+i)) < 0) | ||
largest = s.substring(i, k+i); | ||
else if(smallest.compareTo(s.substring(i, k+i)) > 0) | ||
smallest = s.substring(i, k+i); | ||
} | ||
|
||
|
||
return smallest + "\n" + largest; | ||
} | ||
|
||
|
||
public static void main(String[] args) { | ||
Scanner scan = new Scanner(System.in); | ||
String s = scan.next(); | ||
int k = scan.nextInt(); | ||
scan.close(); | ||
|
||
System.out.println(getSmallestAndLargest(s, k)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class String_tokens{ | ||
|
||
public static void main(String[] args) { | ||
Scanner scan = new Scanner(System.in); | ||
String s; | ||
try{ | ||
s = scan.nextLine(); | ||
} | ||
catch(Exception e){ | ||
s = ""; | ||
} | ||
// Write your code here. | ||
s = s.trim(); | ||
if(s.equals("") || s == null || s.length() == 0) | ||
System.out.println(0); | ||
else{ | ||
String[] words = s.split("['.,?!@\\s_']+"); | ||
System.out.println(words.length); | ||
for(String string : words) | ||
System.out.println(string); | ||
} | ||
scan.close(); | ||
} | ||
} | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters