Solution to a problem typing practice P5587 []

P5587 typing practice

Want to send a more concise and understandable explanations, the code looks long, in fact, is well understood, but a lot of the writing on the line of symmetry

A string attendance problem, when the game Small konjacTune an hour did not tune outHas been RE, pit or a lot(Mainly because I too much water)

  1. After listening to other explanations, said 50% of the data is also a case of Pham Van backspace key

  2. Doing determines the backspace key is not enough, because there may be multiple backspace character to delete the current more than (50% doing side Analyzing data also seem WA), may be with a stack

  3. Computation time t should be turned into double time and then divided by 60, or t <60 when divided by 60 to 0, the answer will be divided by t RE

If you are using an array of characters and then you can use gets strlen, but the `gets' function is dangerous and should not be used., Seems to be some point in WA

I did this problem on the basis of a string of operations such as read, or have consolidated. .

#include<cstdio>
#include<iostream>
#include<cstring>
#include<stack>
using namespace std;
string a[10005],b[10005];
stack<char> aa,bb;//储存去除退格后的字符
int n,m,cnt,t,al,bl;
int main() {
    for (n=1; ; n++) {
        getline(cin,a[n]);
        if (a[n][0]=='E' && a[n][1]=='O' && a[n][2]=='F' && a[n][3]=='\0') break;
    }
    for (m=1; ; m++) {
        getline(cin,b[m]);
        if (b[m][0]=='E' && b[m][1]=='O' && b[m][2]=='F' && b[m][3]=='\0') break;
    }

    for (int i=1; i<n; i++) {
        al=a[i].size(),bl=b[i].size();

        while(!aa.empty()) aa.pop();
        while(!bb.empty()) bb.pop();

        for (int j=0; j<al; j++)
            if (a[i][j]=='<') {
                if (!aa.empty())
                    aa.pop();
            } else aa.push(a[i][j]);//先扫一遍字符串,处理退格,将去除退格后的字符串存入栈
            
        for (int j=0; j<bl; j++) 
            if (b[i][j]=='<') {
                if (!bb.empty())
                    bb.pop();
            } else bb.push(b[i][j]);

        while(aa.size()<bb.size()) bb.pop();
        while(aa.size()>bb.size()) aa.pop();//调为相同长度再比较

        while(!aa.empty()) {
            if (aa.top()==bb.top()) cnt++;//统计答案
            aa.pop(),bb.pop();
        }
    }

    scanf("%d",&t);
    double time=1.0*t/60;
    printf("%d",(int)(cnt/time+0.5));//四舍五入
}

Guess you like

Origin www.cnblogs.com/Randolph68706/p/11824198.html