6.5 Rating补题

C题

c题自己以为是搜索,自己还是考虑少了,但是实则暴力就可以,通过这个题自己也学到了一个新的遍历的方式。

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int INF = 0x3f3f3f3f;

string a;
string b;

int main(){
    cin >> a >> b;

    int len1 = a.length();
    int len2 = b.length();
    int ans = INF;
    int len = len2;

    if(len1<len2){
          swap(a,b);
          swap(len1,len2);
    }

    for(int i = 1; i < len2; i++){
           int num = 0;
        for(int k = i, j = 0; k < len2 && j < len1; k++, j++){
           if(b[k] == a[j])
            num++;
        }
        ans = min(ans, len-num);
    }

    for(int i = 0; i < len1; i++){
        int num = 0;
        for(int k = i, j = 0; j < len2 && k < len1; j++, k++)
            if(a[k] == b[j])
                num++;

        ans = min(ans, len-num);
    }
    printf("%d\n", ans);

    return 0;
}

D题

D题思考起来太绕了,尤其是题干,刚开始说只有一个罪犯,下面又说至少一个罪犯,在补题之前我甚至也一直以为罪犯不止一个。

#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

const int INF = 0x3f3f3f3f;

typedef long long  LL;

const int N = 1e5 + 300;

int a[N];
int issuspect[N], nosuspect[N];
int iscrimer[N], crimer[N];

int main(){
    int n, m;
    while(scanf("%d%d",&n,&m)!=EOF){
        int nosupn = 0;
        for(int i = 1; i <= n; i++){
            scanf("%d",&a[i]);
            if(a[i] > 0){
                issuspect[a[i]]++;
            }else{
                nosuspect[-a[i]]++;
                nosupn++;
            }
        }
        int saytrue = 0;
        int cn = 0;
        for(int i = 1; i <= n; i++){
            saytrue = issuspect[i] + nosupn - nosuspect[i];
            if(saytrue == m){
                crimer[cn] = i; cn++;
                iscrimer[i] = 1;
            }
        }
        if(cn == 1){
            for(int i = 1; i <= n; i++){
                if(a[i] > 0){
                    if(iscrimer[a[i]]){
                        puts("Truth");
                    }else{
                        puts("Lie");
                    }
                }else{
                    if(iscrimer[-a[i]]){
                        puts("Lie");
                    }else{
                        puts("Truth");
                    }
                }
            }
        }else{
            for(int i = 1; i <= n; i++){
                if(a[i] > 0){
                    if(iscrimer[a[i]]){
                        puts("Not defined");
                    }else{
                        puts("Lie");
                    }
                }else{
                    if(iscrimer[-a[i]]){
                        puts("Not defined");
                    }else{
                        puts("Truth");
                    }
                }
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值