STL list的練習

  1. /* 
  2. 沒啥好說的。list的練習 
  3. 題目描述 
  4. ACboy was kidnapped!!  
  5. he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(. 
  6. As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the gate of the maze, the monste say :" I have heard that you are very clever, but if can't solve my problems, you will die with ACboy." 
  7. The problems of the monster is shown on the wall: 
  8. Each problem's first line is a integer N(the number of commands), and a word "FIFO" or "FILO".(you are very happy because you know "FIFO" stands for "First In First Out", and "FILO" means "First In Last Out"). 
  9. and the following N lines, each line is "IN M" or "OUT", (M represent a integer). 
  10. and the answer of a problem is a passowrd of a door, so if you want to rescue ACboy, answer the problem carefully! 
  11. */  

  1. #include <cstdio>  
  2. #include <cmath>  
  3. #include <cstdlib>  
  4. #include <ctime>  
  5.   
  6. #include <iostream>  
  7. #include <cmath>  
  8. #include <algorithm>  
  9. #include <numeric>  
  10. #include <list>  
  11. #include <utility>  
  12.   
  13. #include <cstring>  
  14. #include <vector>  
  15. #include <queue>  
  16. #include <map>  
  17. #include <string>  
  18. #include <memory.h>  
  19. using namespace std;  
  20.   
  21. #define inf 0x3f3f3f3f  
  22. #define MAXN 1000  
  23. #define clr(x,k) memset((x),(k),sizeof(x))  
  24. #define cpy(x,k) memcpy((x),(k),sizeof(x))  
  25. #define Base 10000  
  26.   
  27. #define max(a,b) ((a)>(b)?(a):(b))  
  28. #define min(a,b) ((a)<(b)?(a):(b))  
  29.   
  30. int main(){  
  31.    // freopen("1702.in","r",stdin);  
  32.     list<int> li;  
  33.     char s[100];  
  34.     int t,n,num;  
  35.     scanf("%d",&t);  
  36.     while(t--){  
  37.         scanf("%d %s",&n,s);  
  38.         li.clear();  
  39.             if(!strcmp("FIFO",s)){  
  40.                 for(int zz = 0;zz < n;zz++){  
  41.                     scanf("%s",s);  
  42.                     if(s[0]=='I'){  
  43.                         scanf("%d",&num);  
  44.                         li.push_back(num);  
  45.                     }else{  
  46.                         if(li.empty()){  
  47.                             printf("None\n");  
  48.                         }  
  49.                         else{  
  50.                             printf("%d\n",li.front());  
  51.                             li.pop_front();  
  52.                         }  
  53.                     }  
  54.                 }  
  55.             }else{  
  56.                 for(int zz = 0;zz < n;zz++){  
  57.                     scanf("%s",s);  
  58.                     if(s[0]=='I'){  
  59.                         scanf("%d",&num);  
  60.                         li.push_back(num);  
  61.                     }else{  
  62.                         if(li.empty()){  
  63.                             printf("None\n");  
  64.                         }else{  
  65.                             printf("%d\n",li.back());  
  66.                             li.pop_back();  
  67.                         }  
  68.                     }  
  69.                 }  
  70.             }  
  71.     }  
  72.     return 0;  
  73. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章