Skip to content

Commit 48fb1b2

Browse files
authored
Merge pull request #12 from EunjiShin/master
[3주차]
2 parents dda6145 + 4d9fda0 commit 48fb1b2

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.io.*;
2+
3+
public class problem2231 {
4+
public static void main(String[] args) throws IOException{
5+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
6+
int N = Integer.parseInt(br.readLine());
7+
8+
for(int i=1; i<N; i++){
9+
int number = i;
10+
int sum = 0;
11+
12+
while(number != 0){
13+
sum += number % 10;
14+
number /= 10;
15+
}
16+
17+
if(sum+i == N){
18+
System.out.println(i);
19+
return;
20+
}
21+
}
22+
23+
System.out.println(0);
24+
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
import java.util.StringTokenizer;
3+
4+
public class problem2798 {
5+
public static void main(String[] args) throws IOException{
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
StringTokenizer st = new StringTokenizer(br.readLine());
8+
9+
int N = Integer.parseInt(st.nextToken());
10+
int M = Integer.parseInt(st.nextToken());
11+
12+
int [] number = new int[N];
13+
st = new StringTokenizer(br.readLine(), " ");
14+
for(int i=0; i<N; i++){
15+
number[i] = Integer.parseInt(st.nextToken());
16+
}
17+
18+
int sum = 0;
19+
for(int i=0; i<N; i++){
20+
for(int j=i+1; j<N; j++){
21+
for(int n=j+1; n<N; n++){
22+
int numberSum = number[i] + number[j] + number[n];
23+
sum = (numberSum > sum)&&(M >= numberSum) ? numberSum : sum;
24+
}
25+
}
26+
}
27+
28+
System.out.println(sum);
29+
30+
31+
}
32+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import java.util.Arrays;
2+
3+
class Solution {
4+
public int[] solution(int[] answers) {
5+
int[] answer = {};
6+
int max = 0;
7+
int count = 0;
8+
9+
int[] a = new int[]{1,2,3,4,5};
10+
int[] b = new int[]{2,1,2,3,2,4,2,5};
11+
int[] c = new int[]{3,3,1,1,2,2,4,4,5,5};
12+
13+
int[] score = new int[3];
14+
15+
for(int i=0; i<answers.length; i++){
16+
if(answers[i] == a[i%5]) score[0]++;
17+
if(answers[i] == b[i%8]) score[1]++;
18+
if(answers[i] == c[i%10]) score[2]++;
19+
}
20+
21+
max = Math.max(Math.max(score[0], score[1]), score[2]);
22+
23+
for(int i=0; i<3; i++){
24+
if(max == score[i]) count++;
25+
}
26+
answer = new int[count];
27+
28+
int j = 0;
29+
for(int i=0; i<3; i++){
30+
if(score[i] == max) answer[j++] = i+1;
31+
}
32+
33+
34+
return answer;
35+
}
36+
}
37+
38+
// HashMap쓰면 더 빨라지지 않을까 싶었는데 절대 착각이었음..^^
39+
40+
// import java.util.*;
41+
42+
// class Solution {
43+
// public int[] solution(int[] answers) {
44+
// int[] answer = {};
45+
// int max = 0;
46+
// int count = 0;
47+
48+
// int[] a = new int[]{1,2,3,4,5};
49+
// int[] b = new int[]{2,1,2,3,2,4,2,5};
50+
// int[] c = new int[]{3,3,1,1,2,2,4,4,5,5};
51+
52+
// int[] score = new int[3];
53+
// Map<Integer, Integer> score2 = new HashMap<>(){{
54+
// put(0,0);
55+
// put(1,0);
56+
// put(2,0);
57+
// }};
58+
59+
// for(int i=0; i<answers.length; i++){
60+
// if(answers[i] == a[i%5]) score2.put(0, score2.get(0)+1);
61+
// if(answers[i] == b[i%8]) score2.put(1, score2.get(1)+1);
62+
// if(answers[i] == c[i%10]) score2.put(2, score2.get(2)+1);
63+
// }
64+
65+
// max = Collections.max(score2.values());
66+
67+
// for(int i=0; i<3; i++){
68+
// if(max == score2.get(i)) count++;
69+
// }
70+
// answer = new int[count];
71+
72+
// int j = 0;
73+
// for(int i=0; i<3; i++){
74+
// if(score2.get(i) == max) answer[j++] = i+1;
75+
// }
76+
77+
78+
// return answer;
79+
// }
80+
// }

0 commit comments

Comments
 (0)