• pat1022 Digital Library


    这道题麻烦是麻烦点,思路倒是还算简单。

    比较坑的就是最后要用07d%打印。

    还学到了一个挺重要的东西,就是如何读取一行输入中的连续字符串。

    while(cin>>str)
    
    {
    
      char c;
    
      c=getchar();
    
      if(c=='
    ')
    
        break;
    }
    

      

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 10005;
    map<string, set<int>>title;
    map<string, set<int>>author;
    map<string, set<int>>keyword;
    map<string, set<int>>publisher;
    map<string, set<int>>year;
    int n;
    bool cmp(int a, int b)
    {
    	return a > b;
    }
    typedef struct book
    {
    	int digit;
    	string title;
    	string author;
    	string keyword;
    	string publisher;
    	string year;
    }book;
    book books[maxn];
    int main()
    {
    	scanf("%d", &n);
    	int i;
    	for (i = 0; i < n; i++)
    	{
    		scanf("%d", &books[i].digit);
    		getchar();
    		getline(cin, books[i].title);
    		getline(cin, books[i].author);
    		string key;
    		while (cin >> key)
    		{
    			keyword[key].insert(books[i].digit);
    			char c = getchar();
    			if (c == '
    ')
    				break;
    		}
    		getline(cin, books[i].publisher);
    		getline(cin, books[i].year);
    		title[books[i].title].insert(books[i].digit);
    		author[books[i].author].insert(books[i].digit);
    		publisher[books[i].publisher].insert(books[i].digit);
    		year[books[i].year].insert(books[i].digit);
    	}
    	int n;
    	scanf("%d", &n);
    	for (i = 0; i < n; i++)
    	{
    		int query;
    		scanf("%d: ", &query);
    		string str;
    		getline(cin, str);
    		if (query == 1)
    		{
    			printf("%d: ", query);
    			cout << str << endl;
    			if (title[str].size() == 0)
    			{
    				printf("Not Found
    ");
    			}
    			else
    			{
    				set<int>::iterator it = title[str].begin();
    				for (; it != title[str].end(); it++)
    				{
    					printf("%07d
    ", *it);
    				}
    			}
    		}
    		else if (query == 2)
    		{
    			printf("%d: ", query);
    			cout << str << endl;
    			set<int>::iterator it = author[str].begin();
    			if (author[str].size() == 0)
    			{
    				printf("Not Found
    ");
    			}
    			else
    			{
    				for (; it != author[str].end(); it++)
    				{
    					printf("%07d
    ", *it);
    				}
    			}
    		}
    		else if (query == 3)
    		{
    			printf("%d: ", query);
    			cout << str << endl;
    			if (keyword[str].size() == 0)
    			{
    				printf("Not Found
    ");
    			}
    			else
    			{
    				set<int>::iterator it = keyword[str].begin();
    				for (; it != keyword[str].end(); it++)
    				{
    					printf("%07d
    ", *it);
    				}
    			}
    			
    		}
    		else if (query == 4)
    		{
    			printf("%d: ", query);
    			cout << str << endl;
    			set<int>::iterator it = publisher[str].begin();
    			if (publisher[str].size() == 0)
    			{
    				printf("Not Found
    ");
    			}
    			else
    			{
    				for (; it != publisher[str].end(); it++)
    				{
    					printf("%07d
    ", *it);
    				}
    			}
    		}
    		else if (query == 5)
    		{
    			printf("%d: ", query);
    			cout << str << endl;
    			set<int>::iterator it = year[str].begin();
    			if (year[str].size() == 0)
    			{
    				printf("Not Found
    ");
    			}
    			else
    			{
    				for (; it != year[str].end(); it++)
    				{
    					printf("%07d
    ", *it);
    				}
    			}
    		}
    	}
    }
    

      

  • 相关阅读:
    atitit 提升数据库死锁处理总结
    CoreJava_线程并发(堵塞队列):在某个目录下搜索含有某keyword的文件
    HDU 4389——X mod f(x)(数位DP)
    POJ 1182 (经典食物链 /并查集扩展)
    【iOS-Android开发对照】 之 APP入口
    《Pro Android Graphics》读书笔记之第四节
    Android多个Module统一配置相同jar或库的版本号
    教你上传代码到码云(与github一样)
    解决本地项目推送到码云(github),上提示:failed to push some refs to ...
    android adb常用指令
  • 原文地址:https://www.cnblogs.com/legendcong/p/9636288.html
Copyright © 2020-2023  润新知