跳到正文

题解

题解:P17232 [Algo Beat Contest 017 A] 串哈希

weiyc1约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年8月10日
收录
2026年8月15日
更新
2026年11月17日
篇幅
约 1 分钟
题目
P17232

版本

  1. v1当前

解题思路

直接模拟,用 s.find 判断子串是否存在。按题目给定的优先级顺序判断即可,kirai 的优先级最高,一旦匹配立即处理并跳过后续。

核心细节

  • kirai 规则等价于 x=min⁡(x,0)x = \min(x, 0)。
  • 最终输出时注意条件判断。

赛时代码

C++
#include <bits/stdc++.h>
using namespace std;
int n,m,x;
string s;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>m;
    x=m;
    while(n--){
        cin>>s;
        if(s.find("kirai")!=-1) x=min(x,0);
        else if(s.find("daishuki")!=-1) x+=2;
        else if(s.find("shuki")!=-1) x++;
        else x--;
    }
        if(x>0) cout<<x-m;
        else cout<<"shuki";
    return 0;
}
原文