[Luogu]P5587 打字练习

[Luogu]P5587 打字练习

题目链接:

https://www.luogu.com.cn/problem/P5587

解题思路:

字符串处理,考虑多种可能情况:

  1. 范文和输入均可能存在退格没见过范文还带退格的艹

  2. 计算KPM的时候分母可能为0

  3. 输入的行数可能比范文的短或长。

输入输出样例

Input1:

hello world.
aaabbbb
x
EOF
heelo world.
aaacbbbb
y<x
EOF
60

Output1:

18

Input2:

<<qwe
EOF
<<qwe
EOF
60

Output2:

3

Input3:

<qwe
EOF
qw<e
EOF
60

Output3:

1
代码
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f 

typedef long long ll;
using namespace std;

int count(string a,string b){
 int ans=0;
 int length;
 vector<char> c;
 vector<char> d;
 
 length=a.length();
 
 for(int i=0;i<length;i++){
     if(a[i]=='<' && !c.empty())  
         c.pop_back();
     else{
         if(a[i]!='<')
             c.push_back(a[i]);
     }
 }
 
 length=b.length();
 for(int i=0;i<length;i++){
     if(b[i]=='<' && !d.empty())  d.pop_back();
     else{
         if(b[i]!='<')
         d.push_back(b[i]);
   }
     
 }
 
 length = min(c.size(),d.size());
 for(int i=0;i<length;++i)
     ans+= (c[i]==d[i]);
 return ans;
}
int main() {
 int n=0;
 int i=0;
 int time = 0;
 double ans=0.0;
 
 string str;
 string a[100005];
 
 while(1){
     getline(cin,str);
     if(str!="EOF")  a[n++]=str;
     else      break;
 }
 while(1){
     getline(cin,str);
     if(str!="EOF"){
         if(i<n)  ans+=count(a[i++],str);
         else     continue;
     }
     else
         break;
 }
 cin >> time;
 cout << (int)((ans*60/time)+0.5);
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值