공부기록/백준

[백준] 10952번: A+B-5, 10950번: A+B-3, 11021번: A+B-7, 2884번 알람 시계

메델 2023. 1. 31. 21:00

1. 10952번: A+B-5

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while(true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if((a==0) &&(b ==0)) {
				break;
			}
			System.out.println(a+b);
		}
	}	
}

 

2. 10950번: A+B-3

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		
		for(int i=1; i<=t; i++) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			
			System.out.println(a+b);
			
		}
	}
}

 

3. 11021번: A+B-7

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		
		for(int i=1; i<=t; i++) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			
			System.out.println("Case #"+(i)+": "+ (a+b));
			
		}
	}
}

 

4. 2884번 알람 시계

 

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt();
		int m = scanner.nextInt();

		int alarm = (h*60)+ m - 45;
		
		if(h == 0 && m < 45) {
			h = 23; m= 60+m-45;
		}
		else if(h == 0 && m == 45 ){
			h = 0; m = 0;
		}
		else {
			h = alarm/60;
			m = alarm%60;
		}
		System.out.println(h+" "+ m);
		scanner.close();
		
	}

}