SGU 271 Book Pile 양 끝 대기 열

------------
int n,m,k;
deque<string>que;
vector<string>ans;
char cmd[22],c[4];;
int bit;

int main(){
	scanf("%d%d%d",&n,&m,&k);
    que.clear();
    ans.clear();
    for (int i=0;i<n;i++){
        scanf("%s",c);
        que.push_back(c);
    }
    while (sz(que)>k){
        ans.push_back(que.back());
        que.pop_back();
    }
    bit=1;
    for (int i=0;i<m;i++){
        scanf("%s",cmd);
        if (cmd[0]=='R'){
            bit^=1;
        }
        if (cmd[0]=='A'){
            memset(c,0,sizeof(c));
            strncpy(c,cmd+4,strlen(cmd)-5);
            if (bit){
                que.push_front(c);
                if (sz(que)>k){
                    ans.push_back(que.back());
                    que.pop_back();
                }
            }
            else{
                que.push_back(c);
                if (sz(que)>k){
                    ans.push_back(que.front());
                    que.pop_front();
                }
            }
        }
    }
    while (!que.empty()){
        if (bit){
            ans.push_back(que.back());
            que.pop_back();
        }
        else{
            ans.push_back(que.front());
            que.pop_front();
        }
    }
    for (int i=sz(ans)-1;i>=0;i--){
        printf("%s
",ans[i].c_str()); } return 0; }

------------

좋은 웹페이지 즐겨찾기