标签:des c style class blog code
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 2471 | Accepted: 926 |
Description
Input
Output
Sample Input
2 3 101 102 103 3 201 202 203 ENQUEUE 101 ENQUEUE 201 ENQUEUE 102 ENQUEUE 202 ENQUEUE 103 ENQUEUE 203 DEQUEUE DEQUEUE DEQUEUE DEQUEUE DEQUEUE DEQUEUE STOP 2 5 259001 259002 259003 259004 259005 6 260001 260002 260003 260004 260005 260006 ENQUEUE 259001 ENQUEUE 260001 ENQUEUE 259002 ENQUEUE 259003 ENQUEUE 259004 ENQUEUE 259005 DEQUEUE DEQUEUE ENQUEUE 260002 ENQUEUE 260003 DEQUEUE DEQUEUE DEQUEUE DEQUEUE STOP 0
Sample Output
Scenario #1 101 102 103 201 202 203 Scenario #2 259001 259002 259003 259004 259005 260001
1 #include"iostream" 2 #include"map" 3 #include"queue" 4 #include"cstring" 5 #include"string" 6 #include"cstdio" 7 using namespace std; 8 //map<int,int> m; 9 int m[1000006]; 10 queue<int> q;//队伍序号 11 queue<int> qq[1005];//入队 12 int flag[1005]; 13 int ncase=0; 14 int t,n,ele; 15 void inti(); 16 void input(); 17 void solve(); 18 int main() 19 { 20 while(scanf("%d",&t)==1&&t) 21 { 22 inti(); 23 input(); 24 solve(); 25 } 26 return 0; 27 } 28 void input() 29 { 30 for(int i=0;i<t;i++) 31 { 32 //cin>>n; 33 scanf("%d",&n); 34 for(int j=0;j<n;j++) 35 { 36 //cin>>ele; 37 scanf("%d",&ele); 38 m[ele]=i; 39 } 40 } 41 } 42 void inti() 43 { 44 for(int i=0;i<t;i++) 45 { 46 flag[i]=0; 47 while(!qq[i].empty()) 48 qq[i].pop(); 49 } 50 while(!q.empty()) 51 q.pop(); 52 } 53 void solve() 54 { 55 string com; 56 int a; 57 //cout<<"Scenario #"<<++ncase<<endl; 58 printf("Scenario #%d\n",++ncase); 59 while(cin>>com,com!="STOP") 60 { 61 if(com=="ENQUEUE") 62 { 63 //cin>>a; 64 scanf("%d",&a); 65 if(!flag[m[a]]) 66 { 67 flag[m[a]]=1; 68 q.push(m[a]); 69 } 70 qq[m[a]].push(a); 71 } 72 else if(com=="DEQUEUE") 73 { 74 int order=q.front(); 75 cout<<qq[order].front()<<endl; 76 qq[order].pop(); 77 if(qq[order].empty()) 78 { 79 q.pop(); 80 flag[order]=0; 81 } 82 } 83 } 84 cout<<endl; 85 }
标签:des c style class blog code
原文地址:http://www.cnblogs.com/767355675hutaishi/p/3760934.html