Exam

版权声明:来自星空计算机团队——申屠志刚 https://blog.csdn.net/weixin_43272781/article/details/84031173

Your friend and you took a true/false exam of n questions. You know your answers, your friend's
answers, and that your friend got k questions correct.
Compute the maximum number of questions you could have gotten correctly.
Input
The rst line of input contains a single integer k.
The second line contains a string of n (1 n 1000) characters, the answers you wrote down.
Each letter is either a `T' or an `F'.
The third line contains a string of n characters, the answers your friend wrote down. Each letter
is either a `T' or an `F'.
The input will satisfy 0 k n.
Output
Print, on one line, the maximum number of questions you could have gotten correctly.
Sample Input and Output
3
FTFFF
TFTTT
2

Sample Input and Output
6
TTFTFFTFTF
TTTTFFTTTT
9
题解:

数学问题

根据小明和朋友的答案相同情况,可以分两种情况

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
using namespace std;
int n,k,ans;
char a[1000+10],b[1000+10];
int main()
{
    scanf("%d",&k);
    scanf("%s",a);
    scanf("%s",b);
    int T=0,F=0;
    n=strlen(a);
    for(int i=0;i<n;i++){
        if(a[i]==b[i])
            T++;
        else
            F++;
    }
    ans=0;
    if(T<=k){
        ans=2*T+F-k;
    }else{
        ans=k+F;
    }
    cout << ans << endl;
    //cout << "Hello world!" << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43272781/article/details/84031173