思路:我对字符串掌握的并不好,所以这篇文章是借鉴另一位博主写的,在这里先感谢洛谷用户AC_duckling
然后,这道题难点是如何读入以及各种特殊情况的解决,不过相信看完代码大家不难理解。博主的快读函数也很用心,建议直接阅读博主文章(链接里第一个解法便是,因为无法单独查看)
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read() {//最后如果有多余的行数,可以直接用快读省略掉int count = 0;char a = getchar();while (a < '0' || a>'9') {a = getchar();}while (a >= '0' && a <= '9') {count = count * 10 + a - '0';a = getchar();}return count;
}
int main() {char s[10005][10005];//去掉退格键后范文char wb[100005];//读入的原文char sr[100005];//读入的输入字符char nw[100005];//处理完退格键后的输入字符int now = 0, count = 0;//now表示范文的行数,ans表示正确的单词数while (1) {now++;gets(wb);if (wb[0] == 'E' && wb[1] == 'O' && wb[2] == 'F' && wb[3] == '\0') {break;}int len = strlen(wb);int ne = 0;//当前真正未删去的字符数量for (int j = 0; j < len; j++) {if (wb[j] == '<') {ne--;ne = max(0, ne);//忽略开头continue;}s[now][ne++] = wb[j];}}for (int i = 1; i < now; i++) {gets(sr);int len = strlen(sr);register int ne = 0;for (int j = 0; j < len; j++) {if (sr[j] == '<') {ne--;ne = max(0, ne);continue;}nw[ne++] = sr[j];}for (int j = 0; j < ne; j++) {//将去除退格键后的字串与范文对比if (nw[j] == s[i][j]) {count++;}}}int t = read();//快读忽略最后的EOF和多余的行数double min = 1.0 * t / 60;//所用的分钟printf("%d", (int)(count * 1.0 / min + 0.5));//四舍五入return 0;
}
侵删:https://www.luogu.com.cn/problem/solution/P5587