zoukankan      html  css  js  c++  java
  • map、set 使用方法 | 1022 图书馆信息查询

    看了答案才知道了这题的各种骚操作,然后敲了一顿骚键盘,然后wa。调了很久,才发现要规格化打印……mdzz……

    注:加粗代码为傻逼规格化打印代码:

    #include <stdio.h>
    #include <memory.h>
    #include <math.h>
    #include <string>
    #include <vector>
    #include <set>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <map>
    
    
    #define I scanf
    #define OL puts
    #define O printf
    #define F(a,b,c) for(a=b;a<c;a++)
    #define FF(a,b) for(a=0;a<b;a++)
    #define FG(a,b) for(a=b-1;a>=0;a--)
    #define LEN 1010
    #define MAX (1<<30)-1
    #define V vector<int>
    
    #define MAP map<string,set<int> > //将名字映射为ID 
    
    using namespace std;
    
    MAP mTitle,mAuthor,mKey,mPublish,mYear;
    
    void query(MAP & mp,string obj) {
        set<int> s=mp[obj];
        if(!s.size()) {
            puts("Not Found");
            return;
        }
        set<int>::iterator it=s.begin();
        while(it!=s.end()) {
            O("%07d
    ",*it);
            it++;
        }
    }
    
    int main() {
    //    freopen("1022.txt","r",stdin);
        int N,id,K,op;
        I("%d",&N) ;
        char buf[1000];
        while(N--) {
            //ID
            I("%d",&id);
            getchar();//处理空格
            //书名
            gets(buf);
            mTitle[string(buf)].insert(id);
            //作者
            gets(buf);
            mAuthor[string(buf)].insert(id);
            //关键词
            while(I("%s",buf))  {
                mKey[string(buf)].insert(id);
                if(getchar()=='
    ') break;
            }
            //出版商
            gets(buf);
            mPublish[string(buf)].insert(id);
            //
            gets(buf);
            mYear[string(buf)].insert(id);
        }
        I("%d",&K) ;
        while(K--) {
            I("%d: ",&op);
            gets(buf);
            O("%d: %s
    ",op,buf);
            switch(op) {
                case 1:
                    query(mTitle,string(buf));
                    break;
                case 2:
                    query(mAuthor,string(buf));
                    break;
                case 3:
                    query(mKey,string(buf));
                    break;
                case 4:
                    query(mPublish,string(buf));
                    break;
                case 5:
                    query(mYear,string(buf));
                    break;
            }
        }
        return 0;
    }

    今日不宜编程……

  • 相关阅读:
    4KB对齐
    小甲鱼PE详解之区块表(节表)和区块(节)(PE详解04)
    策略设计模式与c语言中的函数指针
    包装类类值传第
    java的 clone方法
    ubuntu中maven建的web项目不能将project facet设置为 dynamic web module 3.0
    maven 笔记
    eclipse中xml文件不能自动提示的解决办法
    oracle merge into 的例子
    oracle 常用sql
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8585515.html
Copyright © 2011-2022 走看看