题解:P17232 [Algo Beat Contest 017 A] 串哈希
解题思路
直接模拟,用 s.find 判断子串是否存在。按题目给定的优先级顺序判断即可,kirai 的优先级最高,一旦匹配立即处理并跳过后续。
核心细节
kirai规则等价于x = \min(x, 0) 。- 最终输出时注意条件判断。
赛时代码
#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;
}