Skip to content

Commit ca6a314

Browse files
committed
Add some solution #2
1 parent e14fffa commit ca6a314

9 files changed

Lines changed: 633 additions & 0 deletions

File tree

src/AppleAndOrange/Solution.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package AppleAndOrange;
2+
3+
import java.io.*;
4+
import java.math.*;
5+
import java.security.*;
6+
import java.text.*;
7+
import java.util.*;
8+
import java.util.concurrent.*;
9+
import java.util.regex.*;
10+
11+
class Result {
12+
13+
/*
14+
* Complete the 'countApplesAndOranges' function below.
15+
*
16+
* The function accepts following parameters:
17+
* 1. INTEGER s
18+
* 2. INTEGER t
19+
* 3. INTEGER a
20+
* 4. INTEGER b
21+
* 5. INTEGER_ARRAY apples
22+
* 6. INTEGER_ARRAY oranges
23+
*/
24+
25+
public static void countApplesAndOranges(int s, int t, int a, int b, List<Integer> apples, List<Integer> oranges) {
26+
// Write your code here
27+
int appleCount = 0;
28+
int orangeCount = 0;
29+
for (int i = 0; i < apples.size(); i++) {
30+
if (a + apples.get(i) >= s && a + apples.get(i) <= t) appleCount++;
31+
}
32+
33+
System.out.println(appleCount);
34+
35+
for (int j = 0; j < oranges.size(); j++) {
36+
if (b + oranges.get(j) >= s && b + oranges.get(j) <= t) orangeCount++;
37+
}
38+
39+
System.out.println(orangeCount);
40+
}
41+
42+
}
43+
44+
public class Solution {
45+
public static void main(String[] args) throws IOException {
46+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
47+
48+
String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
49+
50+
int s = Integer.parseInt(firstMultipleInput[0]);
51+
52+
int t = Integer.parseInt(firstMultipleInput[1]);
53+
54+
String[] secondMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
55+
56+
int a = Integer.parseInt(secondMultipleInput[0]);
57+
58+
int b = Integer.parseInt(secondMultipleInput[1]);
59+
60+
String[] thirdMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
61+
62+
int m = Integer.parseInt(thirdMultipleInput[0]);
63+
64+
int n = Integer.parseInt(thirdMultipleInput[1]);
65+
66+
String[] applesTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
67+
68+
List<Integer> apples = new ArrayList<>();
69+
70+
for (int i = 0; i < m; i++) {
71+
int applesItem = Integer.parseInt(applesTemp[i]);
72+
apples.add(applesItem);
73+
}
74+
75+
String[] orangesTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
76+
77+
List<Integer> oranges = new ArrayList<>();
78+
79+
for (int i = 0; i < n; i++) {
80+
int orangesItem = Integer.parseInt(orangesTemp[i]);
81+
oranges.add(orangesItem);
82+
}
83+
84+
Result.countApplesAndOranges(s, t, a, b, apples, oranges);
85+
86+
bufferedReader.close();
87+
}
88+
}

src/BetweenTwoSets/Solution.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package BetweenTwoSets;
2+
3+
import java.io.*;
4+
import java.math.*;
5+
import java.security.*;
6+
import java.text.*;
7+
import java.util.*;
8+
import java.util.concurrent.*;
9+
import java.util.function.*;
10+
import java.util.regex.*;
11+
import java.util.stream.*;
12+
import static java.util.stream.Collectors.joining;
13+
import static java.util.stream.Collectors.toList;
14+
15+
class Result {
16+
17+
/*
18+
* Complete the 'getTotalX' function below.
19+
*
20+
* The function is expected to return an INTEGER.
21+
* The function accepts following parameters:
22+
* 1. INTEGER_ARRAY a
23+
* 2. INTEGER_ARRAY b
24+
*/
25+
26+
public static int getTotalX(List<Integer> a, List<Integer> b) {
27+
// Write your code here
28+
int max = a.stream().max(Comparator.comparing(Integer::valueOf)).get();
29+
int min = b.stream().min(Comparator.comparing(Integer::valueOf)).get();
30+
int length = min/max + 1;
31+
int count = 0;
32+
int tempValue;
33+
boolean isNeedContinue = true;
34+
for (int i = 1; i <= length; i++) {
35+
tempValue = max*i;
36+
isNeedContinue = true;
37+
if (tempValue > min) break;
38+
for (int j = 0; j < a.size(); j++) {
39+
if (tempValue % a.get(j) != 0) {
40+
isNeedContinue = false;
41+
break;
42+
}
43+
}
44+
if (!isNeedContinue) continue;
45+
for (int k = 0; k < b.size(); k++) {
46+
if (b.get(k) % tempValue != 0) {
47+
isNeedContinue = false;
48+
break;
49+
}
50+
}
51+
if (isNeedContinue) count++;
52+
}
53+
return count;
54+
}
55+
56+
}
57+
58+
public class Solution {
59+
public static void main(String[] args) throws IOException {
60+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
61+
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
62+
63+
String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
64+
65+
int n = Integer.parseInt(firstMultipleInput[0]);
66+
67+
int m = Integer.parseInt(firstMultipleInput[1]);
68+
69+
List<Integer> arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
70+
.map(Integer::parseInt)
71+
.collect(toList());
72+
73+
List<Integer> brr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
74+
.map(Integer::parseInt)
75+
.collect(toList());
76+
77+
int total = Result.getTotalX(arr, brr);
78+
79+
bufferedWriter.write(String.valueOf(total));
80+
bufferedWriter.newLine();
81+
82+
bufferedReader.close();
83+
bufferedWriter.close();
84+
}
85+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package BirthdayCakeCandles;
2+
3+
import java.io.*;
4+
import java.math.*;
5+
import java.security.*;
6+
import java.text.*;
7+
import java.util.*;
8+
import java.util.concurrent.*;
9+
import java.util.regex.*;
10+
11+
class Result {
12+
13+
/*
14+
* Complete the 'birthdayCakeCandles' function below.
15+
*
16+
* The function is expected to return an INTEGER.
17+
* The function accepts INTEGER_ARRAY candles as parameter.
18+
*/
19+
20+
public static int birthdayCakeCandles(List<Integer> candles) {
21+
// Write your code here
22+
int length = candles.size();
23+
int max = Integer.MIN_VALUE;
24+
int count = 0;
25+
for(int i = 0; i< length; i++) {
26+
if (candles.get(i) > max) {
27+
max = candles.get(i);
28+
count = 1;
29+
} else if (candles.get(i) == max) count++;
30+
}
31+
32+
return count;
33+
34+
}
35+
36+
}
37+
38+
public class Solution {
39+
public static void main(String[] args) throws IOException {
40+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
41+
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
42+
43+
int candlesCount = Integer.parseInt(bufferedReader.readLine().trim());
44+
45+
String[] candlesTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
46+
47+
List<Integer> candles = new ArrayList<>();
48+
49+
for (int i = 0; i < candlesCount; i++) {
50+
int candlesItem = Integer.parseInt(candlesTemp[i]);
51+
candles.add(candlesItem);
52+
}
53+
54+
int result = Result.birthdayCakeCandles(candles);
55+
56+
bufferedWriter.write(String.valueOf(result));
57+
bufferedWriter.newLine();
58+
59+
bufferedReader.close();
60+
bufferedWriter.close();
61+
}
62+
}
63+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package BreakingTheRecords;
2+
3+
import java.io.*;
4+
import java.math.*;
5+
import java.security.*;
6+
import java.text.*;
7+
import java.util.*;
8+
import java.util.concurrent.*;
9+
import java.util.function.*;
10+
import java.util.regex.*;
11+
import java.util.stream.*;
12+
import static java.util.stream.Collectors.joining;
13+
import static java.util.stream.Collectors.toList;
14+
15+
class Result {
16+
17+
/*
18+
* Complete the 'breakingRecords' function below.
19+
*
20+
* The function is expected to return an INTEGER_ARRAY.
21+
* The function accepts INTEGER_ARRAY scores as parameter.
22+
*/
23+
24+
public static List<Integer> breakingRecords(List<Integer> scores) {
25+
// Write your code here
26+
List<Integer> result = new ArrayList<>();
27+
int min, max, countMin, countMax;
28+
min = max = scores.get(0);
29+
countMin =countMax = 0;
30+
for (int i = 0; i < scores.size(); i++) {
31+
if(min > scores.get(i)) {
32+
min = scores.get(i);
33+
countMin++;
34+
}
35+
if(max < scores.get(i)) {
36+
max = scores.get(i);
37+
countMax++;
38+
}
39+
}
40+
result.add(countMax); result.add(countMin);
41+
42+
return result;
43+
44+
}
45+
46+
}
47+
48+
public class Solution {
49+
public static void main(String[] args) throws IOException {
50+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
51+
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
52+
53+
int n = Integer.parseInt(bufferedReader.readLine().trim());
54+
55+
List<Integer> scores = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
56+
.map(Integer::parseInt)
57+
.collect(toList());
58+
59+
List<Integer> result = Result.breakingRecords(scores);
60+
61+
bufferedWriter.write(
62+
result.stream()
63+
.map(Object::toString)
64+
.collect(joining(" "))
65+
+ "\n"
66+
);
67+
68+
bufferedReader.close();
69+
bufferedWriter.close();
70+
}
71+
}

src/GradingStudents/Solution.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package GradingStudents;
2+
3+
import java.io.*;
4+
import java.math.*;
5+
import java.security.*;
6+
import java.text.*;
7+
import java.util.*;
8+
import java.util.concurrent.*;
9+
import java.util.regex.*;
10+
11+
class Result {
12+
13+
/*
14+
* Complete the 'gradingStudents' function below.
15+
*
16+
* The function is expected to return an INTEGER_ARRAY.
17+
* The function accepts INTEGER_ARRAY grades as parameter.
18+
*/
19+
20+
public static List<Integer> gradingStudents(List<Integer> grades) {
21+
// Write your code here
22+
List<Integer> result = new ArrayList<>();
23+
int length = grades.size();
24+
int tempScore = 0;
25+
int tempFive = 0;
26+
for (int i = 0; i < length; i++) {
27+
tempScore = grades.get(i);
28+
tempFive = tempScore/5;
29+
if ((tempFive+1)*5 - tempScore < 3 && (tempFive+1)*5 >= 40) tempScore = (tempFive+1)*5;
30+
result.add(tempScore);
31+
}
32+
return result;
33+
34+
}
35+
36+
}
37+
38+
public class Solution {
39+
public static void main(String[] args) throws IOException {
40+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
41+
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
42+
43+
int gradesCount = Integer.parseInt(bufferedReader.readLine().trim());
44+
45+
List<Integer> grades = new ArrayList<>();
46+
47+
for (int i = 0; i < gradesCount; i++) {
48+
int gradesItem = Integer.parseInt(bufferedReader.readLine().trim());
49+
grades.add(gradesItem);
50+
}
51+
52+
List<Integer> result = Result.gradingStudents(grades);
53+
54+
for (int i = 0; i < result.size(); i++) {
55+
bufferedWriter.write(String.valueOf(result.get(i)));
56+
57+
if (i != result.size() - 1) {
58+
bufferedWriter.write("\n");
59+
}
60+
}
61+
62+
bufferedWriter.newLine();
63+
64+
bufferedReader.close();
65+
bufferedWriter.close();
66+
}
67+
}
68+

0 commit comments

Comments
 (0)