-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commited rest of the files, check for setting a properly package
- Loading branch information
1 parent
5e8284f
commit 6dccb5f
Showing
91 changed files
with
3,102 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,102 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
public class AnonymousThreat { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
String[] input = scanner.nextLine().split("\\s+"); | ||
List<String> list = new ArrayList<>(); | ||
|
||
for (int i = 0; i < input.length; i++) { | ||
list.add(input[i]); | ||
} | ||
|
||
String line = scanner.nextLine(); | ||
while (!line.equals("3:1")) { | ||
String[] tokens = line.split("\\s+"); | ||
String command = tokens[0]; | ||
|
||
if (command.equals("merge")) { | ||
list = giveMergeElements(tokens, list); | ||
|
||
} else if (command.equals("divide")) { | ||
list = giveDivideList(tokens, list); | ||
} | ||
|
||
line = scanner.nextLine(); | ||
} | ||
for (String string : list) { | ||
System.out.print(string + " "); | ||
} | ||
} | ||
|
||
private static List<String> giveMergeElements(String[] tokens, List<String> list) { | ||
int startIndex = Integer.parseInt(tokens[1]); | ||
int lastIndex = Integer.parseInt(tokens[2]); | ||
|
||
if (startIndex < 0) { | ||
startIndex = 0; | ||
} | ||
if (lastIndex > list.size() - 1) { | ||
lastIndex = list.size() - 1; | ||
} | ||
|
||
int counter = startIndex; | ||
for (int i = startIndex; i < lastIndex; i++) { | ||
String concatenated = list.get(counter) + list.get(counter + 1); | ||
list.set(counter, concatenated); | ||
list.remove(counter + 1); | ||
} | ||
return list; | ||
} | ||
|
||
private static List<String> giveDivideList(String[] tokens, List<String> list) { | ||
int index = Integer.parseInt(tokens[1]); | ||
int partition = Integer.parseInt(tokens[2]); | ||
|
||
if (index >= 0 && index < list.size() && partition >= 0 && partition <= 100) { | ||
String element = list.get(index); | ||
List<String> newList = new ArrayList<>(); | ||
|
||
if (element.length() % partition == 0) { | ||
int portionsLength = element.length() / partition; | ||
int count = 0; | ||
for (int i = 0; i < partition; i++) { | ||
String concatenate = ""; | ||
for (int j = 0; j < portionsLength; j++) { | ||
char symbol = element.charAt(count); | ||
concatenate += symbol; | ||
count++; | ||
} | ||
newList.add(concatenate); | ||
} | ||
} else { | ||
int portionsLength = element.length() / partition; // 1 porLen | ||
int count = 0; // 4 | ||
for (int i = 0; i < partition; i++) { // partition 3 | ||
String concatenate = ""; | ||
if (i == partition - 1) { // i 2 | ||
for (int j = count; j < element.length(); j++) { | ||
char symbol = element.charAt(count); | ||
concatenate += symbol; | ||
count++; | ||
} | ||
} else { | ||
for (int j = 0; j < portionsLength; j++) { | ||
char symbol = element.charAt(count); | ||
concatenate += symbol; | ||
count++; | ||
} | ||
} | ||
newList.add(concatenate); | ||
} | ||
} | ||
|
||
list.remove(index); | ||
list.addAll(index, newList); | ||
} | ||
return list; | ||
} | ||
} |
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,18 @@ | ||
import java.util.*; | ||
|
||
public class AppendArrays { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
String[] input = scanner.nextLine().split("\\|"); | ||
List<String> numbers = new ArrayList<>(); | ||
|
||
for (int i = input.length - 1; i >= 0; i--) { | ||
String[] reversedInput = input[i].trim().split("\\s+"); | ||
for (String element : reversedInput) { | ||
numbers.add(element); | ||
} | ||
numbers.remove(""); | ||
} | ||
System.out.println(String.join(" ",numbers)); | ||
} | ||
} |
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,38 @@ | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
import java.util.stream.Collectors; | ||
|
||
public class BombNumbers { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
List<Integer> numbers; | ||
numbers = Arrays.stream(scanner.nextLine().split("\\s+")).map(Integer::parseInt) | ||
.collect(Collectors.toList()); | ||
|
||
String[] input = scanner.nextLine().split("\\s+"); | ||
int bombNumber = Integer.parseInt(input[0]); | ||
int bombPower = Integer.parseInt(input[1]); | ||
|
||
int sum = 0; | ||
|
||
while (numbers.contains(bombNumber)) { | ||
int indexBomb = numbers.indexOf(bombNumber); | ||
|
||
int left = Math.max(0, indexBomb - bombPower); | ||
int right = Math.min(numbers.size() - 1, indexBomb + bombPower); | ||
|
||
for (int i = right; i >= left; i--) { | ||
numbers.remove(i); | ||
} | ||
} | ||
|
||
for (int i = 0; i < numbers.size(); i++) { | ||
sum += numbers.get(i); | ||
} | ||
System.out.println(sum); | ||
} | ||
} | ||
|
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,48 @@ | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
import java.util.stream.Collectors; | ||
|
||
// Judge 75%.. | ||
|
||
public class BombNumbers2 { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
String input = scanner.nextLine(); | ||
List<Integer> numbers = Arrays.stream(input.split("\\s+")) | ||
.map(Integer::parseInt) | ||
.collect(Collectors.toList()); | ||
|
||
String line = scanner.nextLine(); | ||
List<Integer> commands = Arrays.stream(line.split("\\s+")) | ||
.map(Integer::parseInt) | ||
.collect(Collectors.toList()); | ||
|
||
for (int i = 0; i < numbers.size(); i++) { | ||
if (numbers.get(i).equals(commands.get(0))) { | ||
int start = i - commands.get(1); | ||
if (start < 0) { | ||
start = 0; | ||
} | ||
|
||
int finish = i + commands.get(1) + 1; | ||
if (finish > numbers.size()) { | ||
finish = numbers.size(); | ||
} | ||
|
||
//1 2 2 4 2 2 2 9 | ||
for (int j = finish; j > start; j--) { | ||
numbers.remove(j - 1 ); | ||
|
||
} | ||
} | ||
} | ||
|
||
int sum = 0; | ||
for (int i = 0; i < numbers.size(); i++) { | ||
sum += numbers.get(i); | ||
} | ||
System.out.println(sum); | ||
} | ||
} |
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,57 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
public class CardsGame { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
String[] input = scanner.nextLine().split("\\s+"); | ||
List<Integer> deckOne = new ArrayList<>(); | ||
for (int i = 0; i < input.length; i++) { | ||
deckOne.add(Integer.parseInt(input[i])); | ||
} | ||
|
||
String[] input2 = scanner.nextLine().split("\\s+"); | ||
List<Integer> deckTwo = new ArrayList<>(); | ||
for (int i = 0; i < input2.length; i++) { | ||
deckTwo.add(Integer.parseInt(input2[i])); | ||
} | ||
|
||
while (Math.min(deckOne.size(), deckTwo.size()) != 0) { | ||
|
||
if (deckOne.get(0) > deckTwo.get(0)) { | ||
deckOne.add(deckOne.get(0)); | ||
deckOne.add(deckTwo.get(0)); | ||
deckTwo.remove(0); | ||
deckOne.remove(0); | ||
|
||
} else if (deckOne.get(0).equals(deckTwo.get(0))) { | ||
deckOne.remove(0); | ||
deckTwo.remove(0); | ||
|
||
} else if (deckTwo.get(0) > deckOne.get(0)) { | ||
deckTwo.add(deckTwo.get(0)); | ||
deckTwo.add(deckOne.get(0)); | ||
deckOne.remove(0); | ||
deckTwo.remove(0); | ||
} | ||
} | ||
int sum = 0; | ||
if (deckOne.size() == 0) { | ||
|
||
for (Integer value : deckTwo) { | ||
|
||
sum = sum + value; | ||
} | ||
System.out.println("Second player wins! Sum: " + sum); | ||
|
||
} else if (deckTwo.size() == 0) { | ||
|
||
for (Integer value : deckOne) { | ||
sum += value; | ||
} | ||
System.out.println("First player wins! Sum: " + sum); | ||
} | ||
} | ||
} |
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,37 @@ | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
|
||
public class ChangeList { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
String[] inputArr = scanner.nextLine().split("\\s+"); | ||
ArrayList<String> numbers = new ArrayList<>(); | ||
|
||
for (String element : inputArr) { | ||
numbers.add(element); | ||
} | ||
|
||
String input = scanner.nextLine(); | ||
while (!input.equals("end")) { | ||
String[] tokens = input.split("\\s+"); | ||
switch (tokens[0]) { | ||
case "Delete": | ||
while (numbers.contains(tokens[1])) { | ||
numbers.remove(tokens[1]); | ||
} | ||
break; | ||
case "Insert": | ||
String element = tokens[1]; | ||
int index = Integer.parseInt(tokens[2]); | ||
if (index < numbers.size()) { | ||
numbers.add(index,element); | ||
} | ||
break; | ||
} | ||
|
||
input = scanner.nextLine(); | ||
} | ||
System.out.println(String.join(" ",numbers)); | ||
} | ||
} |
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,32 @@ | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class HouseParty { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
ArrayList<String> guestList = new ArrayList<>(); | ||
int n = Integer.parseInt(scanner.nextLine()); | ||
|
||
for (int i = 0; i < n; i++) { | ||
String[] tokens = scanner.nextLine().split("\\s+",2); | ||
String name = tokens[0]; | ||
if (tokens[1].equals("is going!")) { | ||
if (guestList.contains(name)) { | ||
System.out.println(String.format("%s is already in the list!", name)); | ||
} else { | ||
guestList.add(name); | ||
} | ||
} else { | ||
if (guestList.contains(name)) { | ||
guestList.remove(name); | ||
} else { | ||
System.out.println(String.format("%s is not in the list!", name)); | ||
} | ||
} | ||
} | ||
for (String person : guestList) { | ||
System.out.println(person); | ||
} | ||
} | ||
} |
Oops, something went wrong.