[SWEA] 석찬이의 받아쓰기

문제 보러가기

제한사항

이외의 제한사항은 없다.

첫번째 생각

chatAt으로 하나씩 비교하여 카운팅한다.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int tc=1;tc<=T; tc++) {
			int N = sc.nextInt();
			sc.nextLine();
			String A = sc.nextLine();
			String B = sc.nextLine();
			int cnt = 0; 
			for(int n=0; n<N; n++) {
				if ( A.charAt(n) == B.charAt(n) ) {
					cnt++;
				}
			}
			System.out.println("#"+tc+" "+cnt);
		}
	}
}