zoukankan      html  css  js  c++  java
  • 1029. 整理书架

    Description

    二哥又要整理书架了。他整理书架的方法很简单,把书架上一排所有的书全部挪到另一排的后面。现在二哥把它整理的顺序告诉你,你来告诉他整理之后的书架是什么样子的。

    Input Format

    读入一个数 n100

    ,表示书架一共有n排,接下来有n行,每行有一些数字(不多于100个数),每个数字代表一本书,每一行表述这一排书架上的书。再下来有n-1个数对,数对x,y表示把第x排的书放到第y排的后面。

    Output Format

    输出只有一行,输出最后一排的所有书。

    Sample Input

    3
    1 2 3
    4 5
    6 7
    3 1
    2 1
    

    Sample Output

    1 2 3 6 7 4 5
    




        #include <iostream>
        #include <stdio.h>
        #include <queue>

        using namespace std;


        int main() {
            int n;
            cin>>n;
            vector<queue<int> > bookrack;

            for(int i=0;i<=n;i++){
                queue<int> q;
                char c;
                int j=1;
                while((c=getchar())!=' '){
                    if(c>='0' && c<='9'){
                        int a;
                        ungetc(c,stdin);
                        cin>>a;
                        q.push(a);
                    }
                }
                bookrack.push_back(q);
            }

            int ope[n-1][2];
            //cout<<n-1<<endl;
            for(int i=0;i<n-1;i++){
                int a,b;
                cin>>a>>b;
                ope[i][0] = a;
                ope[i][1] = b;
            }

            for(int op = 0; op< n-1; op++){
                int fr = ope[op][0], to = ope[op][1];
                while(!bookrack[fr].empty()){
                    bookrack[to].push(bookrack[fr].front());
                    bookrack[fr].pop();
                }
            }

            for(int i = 0; i<bookrack.size();i++){
                while(!bookrack[i].empty()){
                    cout<<bookrack[i].front()<<" ";
                    bookrack[i].pop();
                }
            }




            return 0;
        }


  • 相关阅读:
    mysql优化之索引优化
    mysqld --debug-sync
    mysql.cnf 配制文件详解
    my.cnf 中字符集设置
    tcp_tw_reuse 与 net.ipv4.tcp_tw_recycle
    mysql init_connect 参数的其他用处
    监控mysql索引使用效率的脚本
    mysql 源代码学习 博客 [lock..]
    mysqld with valgrind
    思维导图软件
  • 原文地址:https://www.cnblogs.com/bernieloveslife/p/7966894.html
Copyright © 2011-2022 走看看