Skip to content

Commit 06c26a4

Browse files
committed
Finished several Codeforces and CSES problems.
1 parent 0b8d94f commit 06c26a4

16 files changed

+223
-7
lines changed

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CSES/MissingNumber.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//FAILURE
2+
import java.util.Arrays;
3+
import java.util.Scanner;
4+
5+
public class MissingNumber {
6+
public static void main(String[] args) {
7+
Scanner s = new Scanner(System.in);
8+
long numberOfValues = s.nextLong();
9+
long[] a = new long[(int) numberOfValues];
10+
for(int i = 0; i < a.length; i++) {
11+
a[i] = s.nextLong();
12+
}
13+
14+
Arrays.sort(a);
15+
16+
long[] total = new long[(int) (numberOfValues + 1)];
17+
Arrays.parallelSetAll(total, i -> i + 1);
18+
19+
for(int i = 0; i < total.length; i++) {
20+
total[i] += (a[0] - 1);
21+
}
22+
23+
for(int i = 0; i < a.length; i++) {
24+
if(a[i] == total[i]) {
25+
continue;
26+
} else {
27+
System.out.println(total[i]);
28+
break;
29+
}
30+
}
31+
}
32+
}

CSES/WeirdAlgorithm.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//SUCCESS
2+
import java.util.Scanner;
3+
4+
public class WeirdAlgorithm {
5+
public static void main(String[] args) {
6+
Scanner s = new Scanner(System.in);
7+
long n = s.nextLong();
8+
weirdAlgorithm(n);
9+
}
10+
11+
public static void weirdAlgorithm(long number) {
12+
System.out.print(number + " ");
13+
while(number != 1) {
14+
if(number % 2 == 0) {
15+
number /= 2;
16+
} else {
17+
number *= 3;
18+
number++;
19+
}
20+
System.out.print(number + " ");
21+
}
22+
}
23+
24+
}

Codeforces/BeautifulMatrix.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//SUCCESS
2+
import java.util.Scanner;
3+
4+
public class BeautifulMatrix {
5+
public static void main(String[] args) {
6+
Scanner s = new Scanner(System.in);
7+
char[][] matrix = new char[5][5];
8+
for (int i = 0; i < 5; i++)
9+
matrix[i] = s.nextLine().replaceAll(" ", "").toCharArray();
10+
int row = -1;
11+
int column = -1;
12+
for (int i = 0; i < 5; i++) {
13+
for (int j = 0; j < 5; j++) {
14+
if (matrix[i][j] == '1') {
15+
row = i;
16+
column = j;
17+
break;
18+
}
19+
}
20+
}
21+
int numberOfMoves = Math.abs(row - 2) + Math.abs(column - 2);
22+
System.out.println(numberOfMoves);
23+
}
24+
}

Codeforces/BitPlusPlus.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//SUCCESS
2+
import java.util.Scanner;
3+
4+
public class BitPlusPlus {
5+
public static void main(String[] args) {
6+
Scanner s = new Scanner(System.in);
7+
int numberOfInputs = s.nextInt();
8+
int x = 0;
9+
String a = "X++";
10+
String b = "++X";
11+
String[] expressions = new String[numberOfInputs];
12+
for(int i = 0; i < numberOfInputs; i++) {
13+
String y = s.next();
14+
expressions[i] = y;
15+
}
16+
for(int i = 0; i < numberOfInputs; i++) {
17+
if(expressions[i].equals(a) || expressions[i].equals(b)) {
18+
x++;
19+
} else {
20+
x--;
21+
}
22+
}
23+
System.out.println(x);
24+
}
25+
}

Codeforces/DominoPiling.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//SUCCESS
2+
import java.util.Scanner;
3+
4+
public class DominoPiling {
5+
public static void main(String[] args) {
6+
Scanner s = new Scanner(System.in);
7+
int m = s.nextInt();
8+
int n = s.nextInt();
9+
int area = m * n;
10+
if(area % 2 == 0) {
11+
System.out.println(area / 2);
12+
} else {
13+
System.out.println((area - 1) / 2);
14+
}
15+
}
16+
}

Codeforces/NextRound.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//SUCCESS
2+
import java.util.ArrayList;
3+
import java.util.Scanner;
4+
5+
public class NextRound {
6+
public static void main(String[] args) {
7+
Scanner s = new Scanner(System.in);
8+
int numberOfParticipants = s.nextInt();
9+
int baseline = s.nextInt();
10+
int numberAdvancing = 0;
11+
ArrayList<Integer> scores = new ArrayList<>();
12+
for(int i = 0; i < numberOfParticipants; i++) {
13+
scores.add(s.nextInt());
14+
}
15+
int minimumScore = scores.get(baseline - 1);
16+
for(int element : scores) {
17+
if((element >= minimumScore) && (element > 0)) {
18+
numberAdvancing++;
19+
}
20+
}
21+
System.out.println(numberAdvancing);
22+
23+
}
24+
}

Codeforces/Team.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//SUCCESS
2+
import java.util.Scanner;
3+
4+
public class Team {
5+
public static void main(String[] args) {
6+
Scanner s = new Scanner(System.in);
7+
int numberOfProblems = s.nextInt();
8+
int a;
9+
int b;
10+
int c;
11+
int numberImplemented = 0;
12+
int placeHolder;
13+
for(int i = 0; i < numberOfProblems; i++) {
14+
a = s.nextInt();
15+
b = s.nextInt();
16+
c = s.nextInt();
17+
placeHolder = a + b + c;
18+
if(placeHolder >= 2) {
19+
numberImplemented++;
20+
}
21+
placeHolder = 0;
22+
}
23+
System.out.println(numberImplemented);
24+
}
25+
}

Codeforces/Watermelon.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//SUCCESS
2+
import java.util.Scanner;
3+
4+
public class Watermelon {
5+
public static void main(String[] args) {
6+
Scanner s = new Scanner(System.in);
7+
int n = s.nextInt();
8+
if(n > 2) {
9+
if (n % 2 == 0) {
10+
System.out.println("YES");
11+
} else {
12+
System.out.println("NO");
13+
}
14+
} else {
15+
System.out.println("NO");
16+
}
17+
}
18+
}

Codeforces/WayTooLongWords.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//SUCCESS
2+
import java.util.ArrayList;
3+
import java.util.Scanner;
4+
5+
public class WayTooLongWords {
6+
public static void main(String[] args) {
7+
Scanner s = new Scanner(System.in);
8+
int amount = s.nextInt();
9+
ArrayList<String> strings = new ArrayList<String>();
10+
while(amount >= 0) {
11+
strings.add(s.nextLine());
12+
amount--;
13+
}
14+
String input;
15+
for(int i = 0; i < strings.size(); i++) {
16+
input = strings.get(i);
17+
if (input.length() > 10) {
18+
System.out.println(Character.toString(input.charAt(0)) + (input.length() - 2) +
19+
Character.toString(input.charAt(input.length() - 1)));
20+
} else {
21+
System.out.println(input);
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)