Lesson 1432 is coming! What about books? (Data Structure entry point)

Source: Internet
Author: User

Description

Last night dd finally made up his mind to tidy up his desk. He had a big box that could hold ten books, so he put all the books he thought he didn't need, of course, it is put in order. If you want to retrieve it, you can retrieve the last book, and then take the second last book... finally, extract the first book.

Result: the next day ...... Dd suddenly found that he wanted to use a book and put it in the box. He had to go to class in five minutes. It would take 10 seconds to extract a book, now he wants to know if he can extract the book he wants within 1 minute.

Another depressing thing is that DD only remembers his entire book publishing process and cannot remember where the book was actually stored ......

Now I want to give you a book release process and the name of the book required by DD, and ask if you can retrieve the book within 60 seconds.

The title is a string of no more than 20 characters. Remember, there are only 10 books in the big box, if there are more than 10 books during the course of writing, or when there is no book in the box, or when there is a book operation, the book is already in the box, this command is invalid. Skip this command (it must be DD's mistake ).

Input

Multiple groups of data, for each group of data:

The first line of the input contains an integer N, indicating that there are N operations, no more than 1000 operations

The second input line contains an integer m, indicating that DD has m books.

The following m rows are the titles of each book;

The following n rows represent N operations, each of which is in one of the following formats:

Book Publishing operation: In Title

Book picking operation: Out

The last line contains a string indicating the name of the book that DD wants (probably not in the box)

Output

Can I get the desired book (6 times at most) for each data output group within the specified time)

If yes can be output, otherwise no can be output.

Solution: Simulate stack operations. The box is a stack and the book is an element. Check whether the overflow condition is the maximum capacity of the box, and then count the time.

 

#include <stdio.h>#include <string.h>main(){int number,te;int shu,op;char a[10][21];char zancun[21];char temp[1001][30];char  c[21];int   i,j,k,t;int   up;int flag;int count;scanf("%d",&number);for(te=1;te<=number;te++){scanf("%d",&op);scanf("%d",&shu);getchar();for(i=0;i<shu;i++){scanf("%s",&temp[i]);}   getchar();for(i=0;i<op;i++){gets(temp[i]);}k=0;flag=0;for(i=1;i<=op;i++){   if(temp[i][0]=='i'){   if(k<10){up=0;for(j=3;temp[i][j]!='\0';j++)zancun[up++]=temp[i][j];zancun[up]='\0';for(t=0;t<k;t++){if(strcmp(zancun,a[t])!=0)                       continue;else break;}if(t==k){strcpy(a[k],zancun);k++;}}elsecontinue;}if(temp[i][0]=='o'){if(k>0)k--;elsek=0;}}getchar();scanf("%s",&c);for(i=0;i<k;i++){if(strcmp(a[i],c)!=0)continue;else{count=i;break;}}if(k-count<6||i==k)printf("yes\n");if(k-count>6&&i!=k)printf("no\n");}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.