01-10 04:27
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ 10820 :: ๋ฌธ์ž์—ด ๋ถ„์„ JAVA ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ 10820 :: ๋ฌธ์ž์—ด ๋ถ„์„ JAVA

miinsun 2022. 3. 15. 17:02

 

๐Ÿ’ฌ  ๋ฌธ์ œ ์„ค๋ช…

๋ฌธ์ž์—ด N๊ฐœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.
์ด๋•Œ, ๋ฌธ์ž์—ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.
๊ฐ ๋ฌธ์ž์—ด์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.

 

๐Ÿ”จ  ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ 

  • ์ฒซ์งธ ์ค„๋ถ€ํ„ฐ N๋ฒˆ์งธ ์ค„๊นŒ์ง€ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 100)
  • ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

 

์ถœ๋ ฅ

  • ์ฒซ์งธ ์ค„๋ถ€ํ„ฐ N๋ฒˆ์งธ ์ค„๊นŒ์ง€ ๊ฐ๊ฐ์˜ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด์„œ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1)

This is String
SPACE    1    SPACE
 S a M p L e I n P u T     
0L1A2S3T4L5I6N7E8

 

์˜ˆ์ œ ์ถœ๋ ฅ 1)

10 2 0 2
0 10 1 8
5 6 0 16
0 8 9 0

 

โ€‹

๐Ÿ’ป  Main.java

/* ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ - 10820 :: ๋ฌธ์ž์—ด ๋ถ„ */
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()) {
			String s = sc.nextLine();
			int sm = 0, bg = 0, i = 0, n = 0; // ์ˆœ์„œ๋ณ„๋กœ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์„ ์ €์žฅํ•œ๋‹ค.
			
			for(char c : s.toCharArray()) {
				if(c == ' ') n++;
				else if (Character.isDigit(c)) i++;
				else {
					if(Character.isUpperCase(c)) bg++;
					else sm++;
				}
			}
			
			System.out.println(sm + " " + bg + " " + i + " "+ n);
		}
		
		sc.close();
	}
}
Comments