
[문제 풀이 완료 목록]
☑️ 최소, 최대
☑️ 최댓값
☑️ 나머지
☑️ 평균
☑️ OX퀴즈
☑️ 평균은 넘겠지
[1차원 배열]
최소, 최대
10818번: 최소, 최대
첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다.
www.acmicpc.net
문제 번호 : 10818
단계 : 1
package jokun.BackJoon.step4;
import java.util.Scanner;
public class Practice10818 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[] numArr = new int[num];
sc.nextLine();
for (int i = 0; i < num; i++) {
numArr[i] = sc.nextInt();
}
int min = numArr[0];
int max = numArr[0];
for (int i = 0; i < numArr.length; i++) {
if(min > numArr[i]){
min = numArr[i];
}
if(max < numArr[i]){
max = numArr[i];
}
}
System.out.println(min + " " + max);
}
}
최댓값
문제 번호 : 2562
단계 : 2
package jokun.BackJoon.step4;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Practice2562 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Integer> numList = new ArrayList<>();
for (int i = 0; i < 9; i++) {
int num = sc.nextInt();
numList.add(num);
}
System.out.println(Collections.max(numList));
System.out.println(numList.indexOf(Collections.max(numList)) + 1);
}
}
나머지
3052번: 나머지
각 수를 42로 나눈 나머지는 39, 40, 41, 0, 1, 2, 40, 41, 0, 1이다. 서로 다른 값은 6개가 있다.
www.acmicpc.net
문제 번호 : 3052
단계 : 3
package jokun.BackJoon.step4;
import java.util.*;
public class Practice3052 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Set<Integer> numList = new HashSet<>();
for (int i = 0; i < 10; i++) {
int num = sc.nextInt();
numList.add(num % 42);
}
System.out.println(numList.size());
}
}
평균
1546번: 평균
첫째 줄에 시험 본 과목의 개수 N이 주어진다. 이 값은 1000보다 작거나 같다. 둘째 줄에 세준이의 현재 성적이 주어진다. 이 값은 100보다 작거나 같은 음이 아닌 정수이고, 적어도 하나의 값은 0보
www.acmicpc.net
문제 번호 : 1546
단계 : 4
package jokun.BackJoon.step4;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Practice1546 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int subjectNum = sc.nextInt();
sc.nextLine();
List<Integer> subjectScore = new ArrayList<>();
int score = 0;
for (int i = 0; i < subjectNum; i++) {
score = sc.nextInt();
subjectScore.add(score);
}
int max = Collections.max(subjectScore);
int sum = 0;
for (Integer integer : subjectScore) {
sum += integer;
}
System.out.println(sum * 100.0 / subjectNum / max);
}
}
OX퀴즈
8958번: OX퀴즈
"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수
www.acmicpc.net
문제 번호 : 8958
단계 : 5
package jokun.BackJoon.step4;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Practice8958 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for (int i = 0; i < num; i++) {
int cnt = 0;
int fullCnt = 0;
List<Character> oxList = new ArrayList<>();
String ox = sc.next();
for (int j = 0; j < ox.length(); j++) {
oxList.add(ox.charAt(j));
if (oxList.get(j) == 'O'){
cnt = cnt + 1;
}else {
cnt = 0;
}
fullCnt = fullCnt + cnt;
}
System.out.println(fullCnt);
}
}
}
평균은 넘겠지
4344번: 평균은 넘겠지
대학생 새내기들의 90%는 자신이 반에서 평균은 넘는다고 생각한다. 당신은 그들에게 슬픈 진실을 알려줘야 한다.
www.acmicpc.net
문제 번호 : 4344
단계 : 6
package jokun.BackJoon.step4;
import java.util.Scanner;
public class Practice4344 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int C = in.nextInt();
for(int i=0; i<C; i++){
int N[]= new int[in.nextInt()];
int sum=0;
for(int j=0; j<N.length; j++){
int grade = in.nextInt();
N[j] = grade;
sum += grade;
}
double avr=sum/N.length;
double count = 0;
for(int k=0; k<N.length; k++){
if(N[k] > avr){
count++;
}
}
System.out.printf("%.3f",count/N.length*100);
System.out.println("%");
}
}
}
'ProblemSolving > BackJoon' 카테고리의 다른 글
[BackJoon] JAVA 단계별 풀이 : 06. 문자열 (completion) (0) | 2022.09.25 |
---|---|
[BackJoon] JAVA 단계별 풀이 : 05. 함수 (completion) (0) | 2022.09.25 |
[BackJoon] JAVA 단계별 풀이 : 03. 반복문 (completion) (0) | 2022.08.16 |
[BackJoon] JAVA 단계별 풀이 : 02. 조건문 (completion) (0) | 2022.08.12 |
[BackJoon] JAVA 단계별 풀이 : 01. 입출력과 사칙연산 (completion) (0) | 2022.06.05 |