Skip to content

Commit 530cbcc

Browse files
authored
Add files via upload
1 parent 0d9fcab commit 530cbcc

File tree

8 files changed

+566
-0
lines changed

8 files changed

+566
-0
lines changed

Challenges II/bin/Hartals/Main.class

1.23 KB
Binary file not shown.
1.36 KB
Binary file not shown.
6.92 KB
Binary file not shown.
3.05 KB
Binary file not shown.

Challenges II/src/Hartals/Main.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// @JUDGE_ID: 859464 10050 Java "Hartals"
2+
package Hartals;
3+
4+
import java.util.*;
5+
6+
public class Main {
7+
8+
public static void main(String[] args)
9+
{
10+
Scanner s = new Scanner(System.in);
11+
12+
int numCases = s.nextInt();
13+
14+
for(int z = 0; z < numCases; z++)
15+
{
16+
int simulationLength = s.nextInt();
17+
int numParties = s.nextInt();
18+
int[] hartalParams = new int[numParties];
19+
int numHartals = 0;
20+
21+
//collect a hartal parameter for each political party
22+
for(int i = 0; i < numParties; i++)
23+
hartalParams[i] = s.nextInt();
24+
25+
for(int day = 1; day <= simulationLength; day++)
26+
{
27+
//check if it's Friday or Saturday
28+
if((day % 7 != 6) && (day % 7 != 0))
29+
{
30+
for(int h: hartalParams)
31+
{
32+
//check if a Hartal was supposed to occur for each party
33+
if(day % h == 0)
34+
{
35+
numHartals++;
36+
break;
37+
}
38+
}
39+
}
40+
}
41+
42+
System.out.println(numHartals);
43+
}
44+
s.close();
45+
System.exit(0);
46+
}
47+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @JUDGE_ID: 859464 10038 Java "Jolly Jumpers"
2+
package Jolly_Jumpers;
3+
4+
import java.util.Scanner;
5+
6+
public class Main {
7+
8+
public static void main(String[] args) {
9+
Scanner s = new Scanner(System.in);
10+
11+
while (true) {
12+
try {
13+
int[] set = new int[s.nextInt()];
14+
boolean[] jumper = new boolean[set.length];
15+
jumper[0] = true;
16+
boolean nonJumper = false;
17+
18+
// populate array
19+
for (int i = 0; i < set.length; i++)
20+
set[i] = s.nextInt();
21+
22+
// check if absolute difference between two consecutive numbers is in between 0 and n-1
23+
for (int i = 1; i < set.length; i++) {
24+
int diff = Math.abs(set[i] - set[i - 1]);
25+
if (diff > 0 && diff < set.length)
26+
jumper[diff] = true;
27+
}
28+
29+
// check to make sure every number was found
30+
for (boolean b : jumper) {
31+
if (!b) {
32+
nonJumper = true;
33+
break;
34+
}
35+
}
36+
37+
if (nonJumper)
38+
System.out.println("Not jolly");
39+
else
40+
System.out.println("Jolly");
41+
42+
} catch (Exception e) {
43+
s.close();
44+
System.exit(0);
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)