๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][5622][๋‹ค์ด์–ผ]

๋‰ด์ด NUEY 2024. 1. 28. 01:39
๋ฐ˜์‘ํ˜•

import java.util.HashMap;
import java.util.Scanner;

// 5622	๋‹ค์ด์–ผ
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int a = 0;
		int b = 1;
		int res = 0;
		
		String s = "";
		String call = in.next();
		in.close();
		
		HashMap<Integer, String> map = new HashMap<Integer, String>();
		
		for (char i = 'A'; i <= 'Z'; i++) {
			if (7 > b && a % 3 == 0) {
				s = "";
				b++;
			}
			else if (i == 'T' || i == 'W') {
				s = "";
				b++;
			}
			
			s += Character.toString(i);
			
			map.put(b, s);
			
			a++;
		}
		
		for (int i = 0; i < call.length(); i++) {
			for (int j = 2; j <= map.size() + 1; j++) {
				if (map.get(j).indexOf(Character.toString(call.charAt(i))) > -1) {
					res += j + 1;
				}
			}
		}
		
		System.out.println(res);
	}
}
  • map์— ๋‹ค์ด์–ผ์— ๋งž๋Š” ๋ฌธ์ž์—ด๊ฐ’์„ ๋‹ด์•„์ค๋‹ˆ๋‹ค.
  • ์ž…๋ ฅ๊ฐ’๊ณผ ์ผ์น˜ํ•˜๋Š” ๊ฐ’์„ indexOf() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ์ฐพ์•„
  • 1์ดˆ์”ฉ ๋”ํ•ด์„œ ๋‹ค์ด์–ผ์„ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์„ ๋ชจ๋‘ ํ•ฉ์นฉ๋‹ˆ๋‹ค.
๋ฐ˜์‘ํ˜•