문제
이 문제의 포인트는 String 비교이다. 3명의 학생으로 고정이 되어있기 때문에 나는 3명의 답 배열을 저장하여 각각 비교하면서 최대값을 가지고 그것이 모두 같으면 모두 출력하고 한명만 같으면 한명만 출력하는 식으로 코드를 구현하였다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int number=sc.nextInt();
char [] arr1 = {'A','B','C'};
char [] arr2= {'B','A','B','C'};
char [] arr3= {'C','C','A','A','B','B'};
int [] people= new int [3];
int index1=0;
int count1=0;
for(int i=0;i<number;i++)
{
if(str.charAt(i)==arr1[index1])
{
count1++;
}
index1++;
if(index1>=3)
{
index1=0;
}
}
int index2=0;
int count2=0;
for(int i=0;i<number;i++)
{
if(str.charAt(i)==arr2[index2])
{
count2++;
}
index2++;
if(index2>=4)
{
index2=0;
}
}
int index3=0;
int count3=0;
for(int i=0;i<number;i++)
{
if(str.charAt(i)==arr3[index3])
{
count3++;
}
index3++;
if(index3>=6)
{
index3=0;
}
}
people[0]=count1;
people[1]=count2;
people[2]=count3;
int max=Integer.MIN_VALUE;
for(int i=0;i<3;i++)
{
if(max<people[i])
{
max=people[i];
}
}
System.out.println(max);
if(max==people[0])
{
System.out.println("Adrian");
}
if(max==people[1])
{
System.out.println("Bruno");
}
if(max==people[2]) {
System.out.println("Goran");
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
https://www.acmicpc.net/problem/2966
2966번: 찍기
문제 상근이, 창영이, 현진이는 역사와 전통을 자랑하는 Sogang ACM-ICPC Team에 가입하려고 한다. 하지만, 가입하려고 하는 모든 지원자는 C언어 필기시험을 통과해야 한다. 이들은 C언어를 할 줄 모른다. 따라서, 필기시험을 모두 찍으려고 한다. 상근이는 A, B, C, A, B, C, A, B, C, A, B, C, ...와 같이 찍어야 통과할 수 있다고 생각한다. 하지만, 창영이는 B, A, B, C, B, A, B, C, B, A, B
www.acmicpc.net