洛谷P1159 排行榜 模拟

洛谷P1159 排行榜

模拟

DOWN的人 正序 排到前面
UP的人 正序 排在后面
然而要注意 SAME 是不变的
所以说SAME 的位置是固定的,这个要特殊做

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <string>
 4 #include <iostream>
 5 using namespace std ; 
 6 
 7 int n,topu,topd ; 
 8 string up[101],down[101],all[101] ; 
 9 string s,type ; 
10 bool f[101] ; 
11 
12 int main() 
13 {
14     cin>>n ; 
15     topu = 0 ; topd = 0 ; 
16     for(int i=1;i<=n;i++)
17     {
18         cin>>all[ i ]>>type ;
19         if(type[ 0 ]=='D') down[++topd] = all[ i ] ; 
20         if(type[ 0 ]=='S') f[ i ] = 1 ; 
21         if(type[ 0 ]=='U') up[++topu] = all[ i ] ;   
22     }
23     int zd = 1 , zu = 1 ; 
24     for(int i=1;i<=n;i++) 
25     {
26         if( f[ i ] ) 
27         {
28             cout<<all[ i ]<<endl ; 
29             continue ; 
30         }
31         if( zd<=topd ) 
32             cout<<down[zd]<<endl ,zd++ ; 
33         else
34             cout<<up[zu]<<endl ,zu++ ;  
35     }
36     return 0 ; 
37 }
原文地址:https://www.cnblogs.com/third2333/p/7094061.html