首页 > 代码库 > hust 1570 Lazy. Lazy. Laaaaaaaaaaaazy!
hust 1570 Lazy. Lazy. Laaaaaaaaaaaazy!
链接
1570 - Lazy. Lazy. Laaaaaaaaaaaazy!
题意
给出三种按键,caplock,shift,nomal(像正常键盘操作一样) ,输入三串字符串,s1,s2,txt, s1表示是按大写键开时的输入,s2是关时的输入,一次能输入一个字符,问输出txt这串字符串最少需要按多少次按键,默认caplock键是关着的。
样例1解释,abc def defabc ,先按三次nomal,然后按一次caplock,再按三次nomal,所以ans=3+1+3=7;
样例2解释,abc def abcdef, 先按一次caplock,按三次nomal,再按一次caplock,再按三次nomal,所以ans=1+3+1+3=8;
做法
用两个set存s1和s2,然后遍历一次txt,需要判断的就是当前的caplock状态是否和txt[i]的状态符合,如果符合则+1,不符合则+2,具体实现看代码,不懂请留言。
代码
#include<bits/stdc++.h>using namespace std;int main() { string s1, s2, txt; while (cin >> s1 >> s2 >> txt) { set<char> o, f; int ans = 0, i, flag = 0; for (char c : s1) o.insert(c); for (char c : s2) f.insert(c); for (i = 0; i < txt.size(); i++) { if (o.count(txt[i])) if (flag) ans++; else if (ans += 2, o.count(txt[i + 1])) flag = 1; if (f.count(txt[i])) if (!flag) ans++; else if (ans += 2, f.count(txt[i + 1])) flag = 0; } cout << ans << endl; }}
?
hust 1570 Lazy. Lazy. Laaaaaaaaaaaazy!
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。