본문 바로가기

Study/☁️ 1일 1문제

[1일 1문제] 백준 단계별로 풀어보기 11-12번, 1-3번 (11.20~11.24)

728x90
반응형

11.20

A+B - 5

package baekjoon;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

public class java_1120 {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int a, b;
        try{
        	while(true) {
        		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        		a = Integer.parseInt(st.nextToken());
                b = Integer.parseInt(st.nextToken());
                
                if(a==0 && b==0) {
                	break;
                }
                else {
                	bw.write((a+b) + "\n");
                }
            }
        	bw.flush();
        	bw.close();
        } catch (IOException e) {
        	System.out.println("오류 발생");
        }
	}
}

 

11.21

A+B - 4

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        try{
        	StringTokenizer st;
        	while(true) {
        		String line = br.readLine();
    			// if(line == null) {//이클립스에서 작동하지 않음
    			if (line == null || line.equals("")) {
    				break;
    			}
    			st = new StringTokenizer(line);
    			int a = Integer.parseInt(st.nextToken());
    			int b = Integer.parseInt(st.nextToken());
    			bw.write(a + b + "\n");
            }
        	br.close();
        	bw.flush();
        	bw.close();
        } catch (IOException e) {
        	System.out.println("오류 발생");
        }
	}
}

 

11.22

package baekjoon;

import java.util.Scanner;

public class java_1122 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			int num = sc.nextInt();
			a[i] = num;
		}
		int b = sc.nextInt();
		
		int count=0;
		for(int i=0; i<N ;i++) {
			if(a[i]==b)
				count++;
		}
		System.out.println(count);
	}
}

 

11.23

package baekjoon;

import java.util.Scanner;

public class java_1123 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] a = new int[N];
		
		for (int i=0; i<N; i++) {
			int num = sc.nextInt();
			a[i] = num;
		}
		
		for(int i=0; i<N ;i++) {
			if(a[i]<X)
				System.out.print(a[i]+" ");
		}
	}
}

 

11.24

package baekjoon;

import java.util.Scanner;

public class java_1124 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		
		for (int i=0; i<N; i++) {
			int num = sc.nextInt();
			a[i] = num;
		}
		
		int max=a[0];
		int min=a[0];
		
		for(int i=1; i<N ;i++) {
			if(max<a[i])
				max=a[i];
			if(min>a[i])
				min=a[i];
		}
		System.out.println(min+ " "+ max);
	}
}
728x90
반응형