728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ฐ ์ค„์— A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (0 < A, B < 10)

์ถœ๋ ฅ

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค "Case #x: "๋ฅผ ์ถœ๋ ฅํ•œ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1 ๋ณต์‚ฌ

5
1 1
2 3
3 4
9 8
5 2

์˜ˆ์ œ ์ถœ๋ ฅ 1 ๋ณต์‚ฌ

Case #1: 2
Case #2: 5
Case #3: 7
Case #4: 17
Case #5: 7

 

<ํ’€์–ด๋ณด์˜ค์ž>

import java.util.Scanner;

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

๊ฐ„๋‹จํ•œ ์ถœ๋ ฅ๋ฌธ์ œ๋ผ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ด๊ฒฐ!!

์–ด์ œ ๊ณต๋ถ€ํ•œ BufferedReader/Writer๋กœ๋„ ํ•œ๋ฒˆ ํ•ด๋ณผ๊ป˜์š”~~

 

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

public class Solution11021_bf {
	public static void main (String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		
		for (int i=1; i<=T; i++) {
			
			st = new StringTokenizer(br.readLine());
			
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			
			bw.write("Case #"+ i + ": " +  +(a+b) + "\n");
		}
		bw.close();
	}
}

์•„์ง์€ ๋ฒ„ํผ ์“ฐ๊ธฐ ์ข€ ์–ด์ƒ‰ํ•˜๋„ค์š” ใ…Žใ…Žใ…Ž import๋„ ๋งŽ๊ตฌ....

๊ทธ๋ž˜๋„ ์ถœ๋ ฅ์ด ๋น ๋ฅด๋‹ค๊ณ  ํ•˜๋‹ˆ ๊ณ„์† ์‹œ๋„๋Š” ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค

728x90
๋ฐ˜์‘ํ˜•

+ Recent posts