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;
    }

    今日不宜编程……

  • 相关阅读:
    判断点是否在一个任意多边形中
    linux 内存布局以及tlb更新的一些理解
    java(内部类)
    java(面向对象 )
    java(数组及常用简单算法 )
    java(运算符,控制流程语句,函数 )
    deep-in-es6(七)
    Java(标识符,关键字,注释,常量,变量)
    MarkDown study:
    *LeetCode--Ransom Note
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8585515.html
Copyright © 2011-2022 走看看