Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[SW Expert Academy] 4261. 빠른 휴대전화 키패드 본문

SW_Expert

[SW Expert Academy] 4261. 빠른 휴대전화 키패드

코드와이 2021. 2. 10. 17:37

 

문제링크

swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWLL7kaaAPsDFAUW

 

package D4;

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

public class 빠른_휴대전화_키패드 {

	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static StringBuilder sb = new StringBuilder();
	static String[] str = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		
		int T = Integer.parseInt(br.readLine());
		
		for( int tc = 1 ; tc <= T ; tc++) {
			
			sb.append("#" + tc + " " );
			
			st = new StringTokenizer(br.readLine(), " ");
			String input = st.nextToken();
			Integer.parseInt(st.nextToken());
			
			String[] S = br.readLine().split(" ");
			
			int ans = 0;
			
			for(String s : S) {
				boolean f = true;
				if( s.length() != input.length() ) continue;
				
				for( int i = 0 ; i < input.length() ; i++) {
					if ( !str[input.charAt(i) - '0'].contains(s.substring(i, i + 1)) ) {
						f = false;
						break;
					}
				}
				
				if (f) ans+=1;
				
			}
			sb.append(ans);
			System.out.println(sb);
			sb.setLength(0);
		}
	}
}