์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step7] 1152 : ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜ (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 12. 20:57

www.acmicpc.net/problem/1152

 

1152๋ฒˆ: ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜

์ฒซ ์ค„์— ์˜์–ด ๋Œ€์†Œ๋ฌธ์ž์™€ ๋„์–ด์“ฐ๊ธฐ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 1,000,000์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. ๋‹จ์–ด๋Š” ๋„์–ด์“ฐ๊ธฐ ํ•œ ๊ฐœ๋กœ ๊ตฌ๋ถ„๋˜๋ฉฐ, ๊ณต๋ฐฑ์ด ์—ฐ์†ํ•ด์„œ ๋‚˜์˜ค๋Š” ๊ฒฝ์šฐ๋Š” ์—†๋‹ค. ๋˜ํ•œ

www.acmicpc.net


๋ฌธ์ œ

์˜์–ด ๋Œ€์†Œ๋ฌธ์ž์™€ ๋„์–ด์“ฐ๊ธฐ๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ๋ฌธ์ž์—ด์—๋Š” ๋ช‡ ๊ฐœ์˜ ๋‹จ์–ด๊ฐ€ ์žˆ์„๊นŒ? ์ด๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋‹จ, ํ•œ ๋‹จ์–ด๊ฐ€ ์—ฌ๋Ÿฌ ๋ฒˆ ๋“ฑ์žฅํ•˜๋ฉด ๋“ฑ์žฅํ•œ ํšŸ์ˆ˜๋งŒํผ ๋ชจ๋‘ ์„ธ์–ด์•ผ ํ•œ๋‹ค.

์ž…๋ ฅ

์ฒซ ์ค„์— ์˜์–ด ๋Œ€์†Œ๋ฌธ์ž์™€ ๋„์–ด์“ฐ๊ธฐ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 1,000,000์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. ๋‹จ์–ด๋Š” ๋„์–ด์“ฐ๊ธฐ ํ•œ ๊ฐœ๋กœ ๊ตฌ๋ถ„๋˜๋ฉฐ, ๊ณต๋ฐฑ์ด ์—ฐ์†ํ•ด์„œ ๋‚˜์˜ค๋Š” ๊ฒฝ์šฐ๋Š” ์—†๋‹ค. ๋˜ํ•œ ๋ฌธ์ž์—ด์˜ ์•ž๊ณผ ๋’ค์—๋Š” ๊ณต๋ฐฑ์ด ์žˆ์„ ์ˆ˜๋„ ์žˆ๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

The Curious Case of Benjamin Button

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

6

 

์˜ˆ์ œ ์ž…๋ ฅ 2

Mazatneunde Wae Teullyeoyo

 

์˜ˆ์ œ ์ถœ๋ ฅ 2

3

 

์˜ˆ์ œ ์ž…๋ ฅ 3

Teullinika Teullyeotzi

 

์˜ˆ์ œ ์ถœ๋ ฅ 3

2


ํ’€์ด

1. ๋ฌธ์ž์—ด s๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

2. ๋ฌธ์ž์—ด s๋ฅผ " " ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ๋ถ„ํ•ดํ•œ๋‹ค.

3. hasMoreTokens() ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ† ํฐ ๊ฐœ์ˆ˜๋ฅผ ์„ผ๋‹ค.

    => StringTokenizer ํด๋ž˜์Šค ์‚ฌ์šฉ

 

import java.io.*;
import java.util.StringTokenizer;


public class B1152 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		String s = br.readLine();
		int count = 0;
		
		StringTokenizer st = new StringTokenizer(s);
		
		while(st.hasMoreTokens()) {
			st.nextToken();
			count++;
		}
		
		System.out.println(count);

	}

}