문제 10818) 최소, 최대
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int min = 1000000;
int max = -1000000;
int num;
for(int i=0;i<N;i++) {
num = Integer.parseInt(st.nextToken());
if(min> num)
min = num;
if(max<num)
max = num;
}
System.out.println(min + " " + max);
}
}
문제 2562) 최댓값
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int max =0;
int i = 1;
int num;
for(int j=1;j<=9;j++) {
num = Integer.parseInt(br.readLine());
if(max<num) {
max = num;
i = j;
}
}
StringBuilder sb = new StringBuilder();
sb.append(max).append("\n").append(i).append("\n");
System.out.print(sb);
}
}
문제 2577) 숫자의 개수
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int A = Integer.parseInt(br.readLine());
int B = Integer.parseInt(br.readLine());
int C = Integer.parseInt(br.readLine());
int word[] = new int[10];
String num = Integer.toString(A*B*C);
for(int i=0;i<num.length();i++) {
word[((int)num.charAt(i)-'0')]++;
}
StringBuilder sb = new StringBuilder();
for(int i=0;i<word.length;i++) {
sb.append(word[i]).append("\n");
}
System.out.print(sb);
}
}
문제 3052) 나머지
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int result[] = new int[42];
int num;
int count = 0;
for(int i=0;i<10;i++) {
num = Integer.parseInt(br.readLine())%42;
result[num]++;
if(result[num]==1)
count++;
}
System.out.println(count);
}
}
문제 1546) 평균
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int arr[] = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
int M = 0;
double result =0;
for(int i=0;i<arr.length;i++) {
arr[i] = Integer.parseInt(st.nextToken());
if(M < arr[i]) {
M = arr[i];
}
}
for(int i=0;i<arr.length;i++) {
result += (double)arr[i]/M*100;
}
result/=arr.length;
System.out.println(result);
}
}
문제 8958) OX퀴즈
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
String input;
StringBuilder sb = new StringBuilder();
for(int i=0;i<T;i++) {
int score = 1;
int result = 0;
input = br.readLine();
for(int j=0;j<input.length();j++) {
if(input.charAt(j)=='O') {
result+=score;
score++;
}
else {
score=1;
}
}
sb.append(result).append("\n");
}
System.out.print(sb);
}
}
문제 4344) 평균은 넘겠지
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int C = Integer.parseInt(br.readLine());
int N;
StringTokenizer st;
StringBuilder sb = new StringBuilder();
int student[];
for(int i=0;i<C;i++) {
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
student = new int[N];
double average = 0;
int score;
int t =0;
for(int j=0;j<N;j++) {
score = Integer.parseInt(st.nextToken());
average+=score;
student[j]=score;
}
average/=N;
for(int j =0;j<N;j++) {
if(student[j]>average) {
t++;
}
}
sb.append(String.format("%.3f", Math.round((double)t/N*1000*100)/(double)1000)).append("%\n");
}
System.out.print(sb);
}
}