-
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.
- Loading branch information
1 parent
7a0fb64
commit b61ff84
Showing
11 changed files
with
143 additions
and
0 deletions.
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,30 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class ArrayLists { | ||
|
||
public static void main(String[] args) { | ||
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ | ||
Scanner in = new Scanner(System.in); | ||
int n,m,x,y; | ||
ArrayList<ArrayList<Integer>> l = new ArrayList<>(); | ||
n = in.nextInt(); | ||
for(int i = 0; i < n; i++){ | ||
ArrayList<Integer> l1 = new ArrayList<>(); | ||
m = in.nextInt(); | ||
for(int j = 0; j < m; j++) | ||
l1.add(in.nextInt()); | ||
l.add(l1); | ||
} | ||
n = in.nextInt(); | ||
for(int i = 0; i < n; i++){ | ||
x = in.nextInt(); | ||
y = in.nextInt(); | ||
try{ | ||
System.out.println(l.get(x-1).get(y-1)); | ||
}catch(Exception e){ | ||
System.out.println("ERROR!"); | ||
} | ||
} | ||
} | ||
} |
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,29 @@ | ||
import java.util.*; | ||
|
||
public class Array_1D2 { | ||
|
||
public static boolean canWin(int pos, int leap, int[] game) { | ||
// Return true if you can win the game; otherwise, return false. | ||
if(pos < 0 || game[pos] == 1) return false; | ||
if(pos + leap > game.length-1 || pos == game.length-1) return true; | ||
game[pos] = 1; | ||
return canWin(pos-1,leap,game) || canWin(pos+1,leap,game) || canWin(pos+leap,leap,game); | ||
} | ||
|
||
public static void main(String[] args) { | ||
Scanner scan = new Scanner(System.in); | ||
int q = scan.nextInt(); | ||
while (q-- > 0) { | ||
int n = scan.nextInt(); | ||
int leap = scan.nextInt(); | ||
|
||
int[] game = new int[n]; | ||
for (int i = 0; i < n; i++) { | ||
game[i] = scan.nextInt(); | ||
} | ||
|
||
System.out.println( (canWin(0, leap, game)) ? "YES" : "NO" ); | ||
} | ||
scan.close(); | ||
} | ||
} |
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.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
public class Hashsets { | ||
|
||
public static void main(String[] args) { | ||
Scanner s = new Scanner(System.in); | ||
int t = s.nextInt(); | ||
String [] pair_left = new String[t]; | ||
String [] pair_right = new String[t]; | ||
|
||
for (int i = 0; i < t; i++) { | ||
pair_left[i] = s.next(); | ||
pair_right[i] = s.next(); | ||
} | ||
|
||
//Write your code here | ||
HashSet<String> hs = new HashSet<>(t); | ||
for(int i = 0; i < t; i++){ | ||
hs.add(pair_left[i]+", "+pair_right[i]); | ||
System.out.println(hs.size()); | ||
} | ||
|
||
} | ||
} |
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,27 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class Lists { | ||
|
||
public static void main(String[] args) { | ||
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ | ||
Scanner in = new Scanner(System.in); | ||
int len = in.nextInt(); | ||
LinkedList<Integer> list = new LinkedList<>(); | ||
for(int i = 0; i < len; i++) | ||
list.add(in.nextInt()); | ||
int j = in.nextInt(); | ||
for(int i = 0; i < j; i++){ | ||
switch(in.next()){ | ||
case "Insert": | ||
list.add(in.nextInt(), in.nextInt()); | ||
break; | ||
case "Delete": | ||
list.remove(in.nextInt()); | ||
break; | ||
} | ||
} | ||
for(Integer i:list) | ||
System.out.print(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,24 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class Subarray { | ||
|
||
public static void main(String[] args) { | ||
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ | ||
Scanner input = new Scanner(System.in); | ||
Integer n = input.nextInt(); | ||
Integer[] array = new Integer[n]; | ||
for(int i = n-1; i >= 0; i--) | ||
array[i] = input.nextInt(); | ||
Integer negatives = 0; | ||
for(int i = 0; i < n; i++){ | ||
int total = 0; | ||
for(int j = i; j < n; j++){ | ||
total = array[j] + total; | ||
if(total < 0) | ||
negatives++; | ||
} | ||
} | ||
System.out.println(negatives); | ||
} | ||
} |
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