PAT-A 2022.3.5题目(仅含1,3题AC代码)

我是菜鸡,大佬勿喷,AC的只有1,3两题,水平有限,仅供参考。

7-1 Simple Lie Detection (20 分)


在这里插入图片描述

Lie detection usually uses a set of prepared questions to ask the testee, and the result is obtained by analyzing the testee’s reactions. The more advanced technology uses a polygraph (测谎仪) to monitor the physical activities of the testee. Our simple polygraph here is to make a judgment by analyzing the characteristics of the answers to the questions.

First, we ask the testee to complete N multiple choice questions, each with a single answer. Each question has 8 options, which are represented by the lowercase English letters a-h. Then we can obtain a string of length N, consisting of only the lowercase English letters a-h. Score each string, and those whose score exceeds a certain threshold (阈值) T are judged as “suspected liars”. The scoring rules are as follows:

  • the string starts with an f has its score −2;
  • the string ends with an a has its score −1;
  • for every longest segment of answeres where the same letter is chosen
    for consecutive questions, if the segment length is larger than 5,
    the score is to +3;
  • if an a is immediately followed by e or h, the score is to −4;
  • for every longest segment of answeres where consecutively increasing
    letters are chosen to answer consecutive questions (such as abcd or
    defgh), if the segment length is larger than 3, the score is to +5.

Your job is to score the answers and make a judgement.

Input Specification:

Each input file contains one test case. For each case, the first line gives 3 positive integers N (6≤N≤100), the number of questions; T (≤100), the threshold for judging a liar; and K (≤100), the number of testees.
Then K lines follow, each gives the string of answers of a testee.

Output Specification:

For each testee, print in a line the total score of his/her answers. If the score exceeds the threshold, print !!! after the score.

Sample Input:

12 1 6
fghaebcdeddd
ahhhhhhgbaaa
cdefffffffff
fffffghecaaa
feeeeeeeegcb
aaaaaabbbbbb

Sample Output:

-1
-2
8!!!
-3
1
6!!!

AC代码:

#include<iostream>
#include<string>
using namespace std;

int n,t,k;

int judge(string s){
   
    int ans=0;
    if(s[0]=='f')
        ans-=2;
    if(s[n-1]=='a')
        ans-=1;
    for(int i=0;i<n-1;i++){
   
        if( (s[i]=='a' && s[i+1]=='e') || (s[i]=='a' && s[i+1]=='h') )
            ans-=4;
    }
    
    for(int i=
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值