๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[SW Expert Academy] - (D3)9317. ์„์ฐฌ์ด์˜ ๋ฐ›์•„์“ฐ๊ธฐ

by ์ฃผ๋ฐœ2 2020. 5. 25.
๋ฐ˜์‘ํ˜•

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AW-hOY5KeEIDFAVg&categoryId=AW-hOY5KeEIDFAVg&categoryType=CODE

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

์ฝ”๋“œ

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int TC = scan.nextInt();
		for(int t=1; t<=TC; t++) {
			int N = scan.nextInt();
			String str1 = scan.next();	// ๋”ฐ๋ผ ์ ์–ด์•ผํ•˜๋Š” ๋ฌธ์ž์—ด
			String str2 = scan.next();	// ๋”ฐ๋ผ ์ ์€ ๋ฌธ์ž
			int rightWords = 0;	// ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ ์€ ๋ฌธ์ž ๊ฐฏ์ˆ˜
			
			for(int i=0; i<str1.length(); i++) {
				rightWords += (str1.charAt(i) == str2.charAt(i)) ? 1 : 0;
			}
			
			System.out.println("#" + t + " " + rightWords);
		}
		
		scan.close();
	}

}

ํ’€์ด

ํ…Œ์ŠคํŠธ์ผ€์ด์Šค ์ˆ˜๋งŒํผ ๋ฌธ์ž์—ด 2๊ฐœ๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ , ๋‘ ๋ฌธ์ž์—ด์ด ๊ฐ™์œผ๋ฉด ๊ฐฏ์ˆ˜๋ฅผ +1์”ฉ ํ•ด์ฃผ๋ฉด ๋

N์€ ์‚ฌ์šฉ๋˜์ง€๋„ ์•Š๋Š”๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€