본문 바로가기
Problem Solving/Baekjoon

[백준] 16406 Exam - Greedy / Java

by graycode 2023. 12. 21.

 문제 링크

 

16406번: Exam

Your friend and you took the same true/false exam. You know your answers, your friend’s answers, and the number of your friend’s answers that were correct. Compute the maximum possible score you could have gotten

www.acmicpc.net

 

 풀이 코드

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int k = Integer.parseInt(br.readLine());
        String a = br.readLine(), b = br.readLine();

        int cnt = 0;
        for (int i = 0; i < a.length(); i++) if (a.charAt(i) == b.charAt(i)) cnt++;

        bw.write(String.valueOf(a.length() - Math.abs(k - cnt)));
        bw.flush();
    }

}

댓글