-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hard Questions
72 lines (66 loc) · 3.13 KB
/
Hard Questions
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Programmer : Dhruv Patel
* Problem Name : Hard Questions
* Used In : 101 Hack 50
* Used As : Hackerrank.com
* Thoughts =>
* Problem :-
* Vincent and Catherine are classmates who just took an exam in Math 55. The exam consists of multiple-choice questions.
* Each question has choices, each of which is represented by a single capital letter A, B, C, D and E.
* Each question has exactly one correct answer. A student's score is equal to the number of questions he/she correctly answered.
* This was the hardest exam they've ever taken! No one was ever sure of their answer even after the exam, and some students weren't
* even able to answer all the questions.
* The questions were so hard that Vincent and Catherine strongly believe that they can't both be correct in any question.
* In other words, for each question, they believe that one or both of them must be incorrect.
* Now, Vincent wants to know how well he could have performed in the exam.
* Given the answers of Vincent and Catherine, find the maximum score that Vincent could have gotten, assuming that
* they can't both have gotten the correct answer to any particular question.
* Input Format
* The first line contains a single integer , the number of questions.
* The second line contains a string of length denoting the answers of Vincent.
* The third line contains a string of length denoting the answers of Catherine.
* Each answer string consists of only the characters A, B, C, D, E and . (dot character).
* If the i'th character is A, B, C, D or E, then this character represents the student's answer for the 'th question.
* If the i'th character is ., then this means the student gave no answer for the 'th question.
* Constraints
* 1<=n<=100
* Output
* Print a single line containing a single integer denoting the maximum score that Vincent could have gotten assuming that
* they can't both have gotten the correct answer to any particular question.
* Sample Input 0
* 24
* CCACCBAEBAAAAAAAA.......
* CCACCBAEBAAAAAAAA.......
* Sample Output 0
* 0
* Explanation 0
* In this case, Vincent and Catherine answered exactly the same for the whole exam. Since they can't both be correct in
* any question, it means they are both incorrect in every question. Hence, they both score 0.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int maxScoreOfVincent(int n, String s, String t) {
// s = v
// t = c
int i = 0;
int counter = 0;
while(i<n) {
if(s.charAt(i)!=t.charAt(i) & s.charAt(i)!='.'){
counter++;
}
i++;
}
return counter;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// Return the maximum score of Vincent.
int n = in.nextInt();
String s = in.next();
String t = in.next();
int result = maxScoreOfVincent(n, s, t);
System.out.println(result);
}
}