• 1022 Digital Library (30分)


    本题题意很好读,看上去也不难写 写完运行才发现输出title只有一个单词... 后来把cin >> t换成了getline(cin, t) 还有一个坑点: Line #1: the 7-digit ID number; 故输出要用%07d

    采用的数据结构是map<string, set >
    开了很多这样的map

    还有key的读入,也需要记忆

    /**/
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cctype>
    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <set>
    #include <vector>
    #include <string>
    #include <stack>
    #include <queue>
    
    typedef long long LL;
    typedef unsigned long long ULL;
    using namespace std;
    
    bool Sqrt(LL n) { return (LL)sqrt(n) * sqrt(n) == n; }
    const double PI = acos(-1.0), ESP = 1e-10;
    const LL INF = 99999999999999;
    const int inf = 999999999;
    int N, M;
    map<string, set<int> > title, author, key, pub, year;
    
    void Q(map<string, set<int> > & mp, string & str)
    {
    	if(mp.find(str) != mp.end()) {
    		for(auto u : mp[str]) printf("%07d
    ", u);
    		// for(set<int>::iterator it = mp[str].begin(); it != mp[str].end(); it++)
    		// 	printf("%07d
    ", *it);
    	}
    	else puts("Not Found");
    }
    
    int main()
    {
    	//freopen("in.txt", "r", stdin);
    	//freopen("out.txt", "w", stdout);
    	scanf("%d", &N);
    	for(int i = 0; i < N; i++) {
    		int id; scanf("%d
    ", &id);
    		string t; getline(cin, t);
    		title[t].insert(id);
    		getline(cin, t); author[t].insert(id);
    		while(cin >> t) {
    			key[t].insert(id);
    			if(getchar() == '
    ') break;
    		}
    		getline(cin, t); pub[t].insert(id);
    		getline(cin, t); year[t].insert(id);
    	}
    	scanf("%d", &M);
    	while(M--) {
    		int num;
    		string s;
    		scanf("%d: ", &num);
    		getline(cin, s);
    		cout << num << ": " << s << "
    ";
    		if(num == 1) Q(title, s);
    		else if(num == 2) Q(author, s);
    		else if(num == 3) Q(key, s);
    		else if(num == 4) Q(pub, s);
    		else if(num == 5) Q(year, s);
    	}	
    
    	return 0;
    }
    /*
        input:
        output:
        modeling:
        methods:
        complexity:
        summary:
    */
    
  • 相关阅读:
    算法作业实验三
    牛客练习赛53 B 美味果冻
    牛客练习赛53 C 富豪凯匹配串
    bitmat
    牛客挑战赛33 B 鸽天的放鸽序列
    树状数组
    线段树
    2019牛客国庆集训派对day7 A 2016
    背包
    作业三 -并查集
  • 原文地址:https://www.cnblogs.com/000what/p/12203135.html
Copyright © 2020-2023  润新知