标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4429 Accepted Submission(s): 2260
1 #include<stdio.h> 2 #include<string.h> 3 #include<stack>
4 #include<queue>
5 using namespace std; 6 char s1[10],s2[10]; 7 int main() 8 { 9 int n,a,b; 10 11 scanf("%d",&n); 12 while(n--) 13 { 14 queue<int>s;//定义一个队列 15 while(!s.empty()) 16 s.pop(); 17 stack<int>r;//定义一个栈 18 while(!r.empty())
19 r.pop();//一定要每次都要清空队列,要不然各种WA我也是醉了! 20 scanf("%d %s",&a,s1); 21 getchar();//注意吸收回车 22 if(strcmp(s1,"FIFO")==0) 23 { 24 while(a--) 25 { 26 scanf("%s",s2); 27 if(strcmp(s2,"IN")==0) 28 { 29 scanf("%d",&b); 30 getchar(); 31 s.push(b); 32 } 33 else if(strcmp(s2,"OUT")==0) 34 { 35 if(s.empty()) 36 printf("None\n"); 37 else 38 { 39 printf("%d\n",s.front());//输出队首元素 40 s.pop(); 41 } 42 43 } 44 } 45 } 46 else if(strcmp(s1,"FILO")==0) 47 { 48 while(a--) 49 { 50 scanf("%s",s2); 51 if(strcmp(s2,"IN")==0) 52 { 53 scanf("%d",&b); 54 getchar(); 55 r.push(b); 56 } 57 else if(strcmp(s2,"OUT")==0) 58 { 59 if(r.empty()) 60 printf("None\n"); 61 else 62 { 63 printf("%d\n",r.top());//输出栈顶元素 64 r.pop(); 65 } 66 67 } 68 } 69 } 70 } 71 return 0; 72 }
ACboy needs your help again!--hdu1702
标签:
原文地址:http://www.cnblogs.com/Eric-keke/p/4681823.html