๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[Codeforces] 1093A: Dice Rolling

by ์ฃผ๋ฐœ2 2020. 4. 2.
๋ฐ˜์‘ํ˜•

https://codeforces.com/problemset/problem/1093/A

 

Problem - 1093A - Codeforces

 

codeforces.com

์ฝ”๋“œ

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int t = scan.nextInt();
		int count = 0;	// roll ๊ฐฏ์ˆ˜
		for(int tc=0; tc<t; tc++) {
			int x = scan.nextInt();
			/* ์ฃผ์‚ฌ์œ„ ์ค‘ ๊ฐ€์žฅ ํฐ 7๋กœ ์ตœ๋Œ€ํ•œ ์ ์ˆ˜ ๋งž์ถ˜๋‹ค. */
			count = x / 7;
			/* ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š์„๊ฒฝ์šฐ ์ฃผ์‚ฌ์œ„ 1๋ฒˆ ๋”๊ตด๋ ค์•ผํ•จ. */
			count += (x%7 == 0) ? 0 : 1;
			System.out.println(count);
		}
		
		scan.close();
	}

}

ํ’€์ด

์˜ˆ์ œ์™€ ๋‹ค๋ฅด๊ฒŒ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋‹ค.

์ฃผ์‚ฌ์œ„๋Š” 2 ~ 7๊นŒ์ง€๊ณ  ์ฃผ์‚ฌ์œ„์˜ ํ•ฉ์œผ๋กœ x๋ฅผ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ค‘ ํ•˜๋‚˜๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

์ฃผ์‚ฌ์œ„๋ฅผ ์ตœ๋Œ€ํ•œ ์ ๊ฒŒ ์“ฐ๊ธฐ์œ„ํ•ด ์ตœ๋Œ€ํ•œ ์ฃผ์‚ฌ์œ„๋ฉด์ด 7์ธ๊ฒƒ๋งŒ ์‚ฌ์šฉํ•˜๊ณ , ๋‚˜๋จธ์ง€๋Š” ์•„๋ฌด๊ฑฐ๋‚˜ ํ•œ๊ฐœ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€