CT
[BOJ] 4단계 1차원 배열
kinggora
2023. 1. 25. 00:58
| 1 | 10807 | 개수 세기 |
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
String[] arr = reader.readLine().split(" ");
String str = reader.readLine();
for(String s : arr){
if(!s.equals(str))
n--;
}
reader.close();
System.out.print(n);
}
}
| 2 | 10871 | X보다 작은 수 |
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] nx = reader.readLine().split(" ");
String[] arr = reader.readLine().split(" ");
StringBuilder sb = new StringBuilder();
for(int i = 0; i<Integer.parseInt(nx[0]); i++){
if(Integer.parseInt(nx[1])>Integer.parseInt(arr[i])){
sb.append(arr[i] + "\n");
}
}
reader.close();
System.out.print(sb);
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
StringBuilder sb = new StringBuilder();
int num;
for(int i = 0; i < n; i++){
if(x>(num=sc.nextInt())){
sb.append(num +"\n");
}
}
System.out.print(sb);
}
}
| 3 | 10818 | 최소, 최대 |
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int min = 1000001;
int max = -1000001;
int temp;
for(int i=0; i<n; i++){
temp = sc.nextInt();
if(temp < min){
min = temp;
}
if(temp > max){
max = temp;
}
}
System.out.print(min + " " + max);
}
}
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
StringTokenizer st = new StringTokenizer(reader.readLine());
int[] intArr = new int[n];
for(int i = 0; i<n; i++){
intArr[i]= Integer.parseInt(st.nextToken());
}
reader.close();
Arrays.sort(intArr);
System.out.print(intArr[0] + " " + intArr[n-1]);
}
}
*java.util.Arrays 의 sort 메서드 사용
| 4 | 2562 | 최댓값 |
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int index = 0;
int max = -1;
int temp;
for(int i = 1; i <= 9; i++){
temp = Integer.parseInt(reader.readLine());
if(temp > max){
index = i;
max = temp;
}
}
reader.close();
System.out.println(max);
System.out.print(index);
}
}
| 5 | 10810 | 공 넣기 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] split = reader.readLine().split(" ");
int N = Integer.parseInt(split[0]);
int M = Integer.parseInt(split[1]);
int[] bucket = new int[N];
for(int a = 0; a < M; a++) {
String[] arr = reader.readLine().split(" ");
int start = Integer.parseInt(arr[0]);
int offset = Integer.parseInt(arr[1]) - start + 1;
int number = Integer.parseInt(arr[2]);
for(int b = 0; b < offset; b++){
bucket[start+b-1] = number;
}
}
for(int number: bucket) {
System.out.print(number + " ");
}
}
}
| 6 | 10813 | 공 바꾸기 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] split = reader.readLine().split(" ");
int N = Integer.parseInt(split[0]);
int M = Integer.parseInt(split[1]);
int[] bucket = new int[N];
for(int i = 0; i < bucket.length; i++){
bucket[i] = i + 1;
}
for(int a = 0; a < M; a++) {
String[] arr = reader.readLine().split(" ");
int i = Integer.parseInt(arr[0]) - 1;
int j = Integer.parseInt(arr[1]) - 1;
int temp = bucket[i];
bucket[i] = bucket[j];
bucket[j] = temp;
}
for(int num: bucket) {
System.out.print(num + " ");
}
}
}
| 7 | 5597 | 과제 안 내신 분..? |
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
int[] arr = new int[30];
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 28; i++) {
arr[Integer.parseInt(reader.readLine()) - 1] = 1;
}
reader.close();
for (int j = 0; j < arr.length; j++) {
if (arr[j] != 1) {
System.out.println(j + 1);
}
}
}
}
| 8 | 3052 | 나머지 |
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int[] arr = new int[42];
int index;
for(int i=0; i<10; i++){
index = Integer.parseInt(reader.readLine()) % 42;
arr[index]++;
}
reader.close();
int count = 0;
for(int n : arr){
if(n > 0) count++;
}
System.out.print(count);
}
}
| 9 | 10811 | 바구니 뒤집기 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] split = reader.readLine().split(" ");
int N = Integer.parseInt(split[0]);
int M = Integer.parseInt(split[1]);
int[] bucket = new int[N];
for(int i = 0; i < bucket.length; i++) {
bucket[i] = i + 1;
}
for(int i = 0; i < M; i++) {
String[] arr = reader.readLine().split(" ");
int a = Integer.parseInt(arr[0]) - 1;
int b = Integer.parseInt(arr[1]) - 1;
while (a < b) {
int temp = bucket[a];
bucket[a] = bucket[b];
bucket[b] = temp;
a++;
b--;
}
}
for(int num : bucket) {
System.out.print(num + " ");
}
}
}
| 10 | 1546 | 평균 |
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
float[] score = new float[n];
StringTokenizer st = new StringTokenizer(reader.readLine(), " ");
for(int i = 0; i < n; i++){
score[i] = Float.parseFloat(st.nextToken());
}
reader.close();
Arrays.sort(score);
float total = 0;
for(int i = 0; i < n; i++){
total += (score[i]/score[n-1])*100;
}
System.out.print(total/n);
}
}
| 11 | 8958 | OX퀴즈 |
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
StringBuilder sb = new StringBuilder();
for(int i = 0; i<n; i++){
String test = reader.readLine();
int score = 0;
int total = 0;
for(int j = 0; j < test.length(); j++){
if(test.charAt(j) == 'O'){
score++;
total += score;
} else{
score = 0;
}
}
sb.append(total).append("\n");
}
reader.close();
System.out.print(sb);
}
}