【洛谷P5587】打字練習
【P5587】打字練習
【廢話】首先,作為我練習字符串的一道題,很自然的意料之中的遇到了瓶頸
【前置知識】
- 字符的輸入
- ??久遠的記憶讓我以為 gets 還能用,于是就RE了,后來又用
scanf("%[^\n]",s);,但是由于沒有熟練掌握,換為getchar
- ??久遠的記憶讓我以為 gets 還能用,于是就RE了,后來又用
-
-
getchar一次只能進行一個字符的讀入,因此可以每次判斷讀入內(nèi)容后放進字符組里
-
【解題思路】
- 針對于每一組字符都存在一個
stack里 - 比較時候,要先將
stack中的字符先裝進另一個臨時棧中 - 注意
<的處理
【遇到的坑】
- 若只出題人把范文也加了退回
【我的若只CODE】
實現(xiàn)代碼
#include<bits/stdc++.h>
using namespace std;
char s;
stack<char> s1[4001];
long long ans;
int cnt;
signed main()
{
cnt=1;
while(1)
{
s=getchar();
if(s=='F')
{
break;
}
else if(s=='\n')
{
cnt++;
}
else if(s=='<' and !s1[cnt].empty())
{
s1[cnt].pop();
}
else if((s>='a' and s<='z') or s=='.' or s==' ')
{
s1[cnt].push(s);
}
}
int id=0;
while(1)
{
stack<char> t1,t2,s2;
while(1)
{
s=getchar();
if(s=='F')
{
break;
}
else if(s=='\n')
{
break;
}
else if(s=='<' and !s2.empty())
{
s2.pop();
}
else if((s>='a' and s<='z') or s=='.' or s==' ')
{
s2.push(s);
}
}
if(s=='F')
{
break;
}
else
{
while(!s1[id].empty())
{
t1.push(s1[id].top());
s1[id].pop();
// cout<<t1.top()<<endl;
}
id++;
while(!s2.empty())
{
t2.push(s2.top());
s2.pop();
// cout<<t2.top()<<endl;
}
while(!t1.empty() and !t2.empty())
{
if(t1.top()==t2.top())
{
// cout<<t1.top()<<" "<<t2.top()<<endl;
ans++;
}
// cout<<"^^^"<<t1.top()<<" "<<t2.top()<<endl;
t1.pop();
t2.pop();
}
}
}
double io;
cin>>io;
cout<<int(ans*60.0/io+0.5);
}
浙公網(wǎng)安備 33010602011771號