本题题意很好读,看上去也不难写
写完运行才发现输出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\n", u);
// for(set<int>::iterator it = mp[str].begin(); it != mp[str].end(); it++)
// printf("%07d\n", *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\n", &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() == '\n') 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 << "\n";
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:
*/

1022 Digital Library (30分)的更多相关文章

  1. PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)

    1022 Digital Library (30 分)   A Digital Library contains millions of books, stored according to thei ...

  2. 1022 Digital Library (30 分)

    1022 Digital Library (30 分)   A Digital Library contains millions of books, stored according to thei ...

  3. PAT Advanced 1022 Digital Library (30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  4. 【PAT甲级】1022 Digital Library (30 分)(模拟)

    题意: 输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份. 然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没 ...

  5. pat 甲级 1022. Digital Library (30)

    1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...

  6. 1022 Digital Library (30)(30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  7. 1022. Digital Library (30)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  8. 1022. Digital Library (30) -map -字符串处理

    题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...

  9. 1022 Digital Library (30)(30 point(s))

    problem A Digital Library contains millions of books, stored according to their titles, authors, key ...

  10. PAT-1022 Digital Library (30 分) 字符串处理

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

随机推荐

  1. R6-1 数字金字塔

    1 void pyramid(int n) 2 { 3 int i, j; 4 5 for(i = 0;i < n;i++){ 6 for(j = 0;j < n - i - 1;j++) ...

  2. Flink Application Development DataStream API Operators Overview-- Flink应用程序开发DataStream API操作符概览

    目录 概览 DataStream转换 物理分区 任务链和资源组 翻译原文- Application Development DataStream API Operators 概览 操作符将一个或多个D ...

  3. linux 中sed命令如何删除第一列和最后一列

    删除第一列 (base) root@PC1:/home/test# cat test.txt1 MIR1302-10 12 FAM138A 23 OR4F5 34 RP11-34P13.7 45 RP ...

  4. ORACLE备份脚本(3-RMAN0级全备)

    创建目录 mkdir  -p  /bak/level0 mkdir  -p  /bak/arch chown -R oracle:oinstall  /bak/ vi  rmanlevel0.sh # ...

  5. MAC截图快捷键有哪些?

    在日常办公的时候,在遇到问题的时候使用截图会比打字方便的多,因为使用最频繁的是Windows系统,所以习惯用windows的截图快捷键进行截图.这时你会发现在MAC中这些快捷方式都是无效的,那么MAC ...

  6. JavaScript 调用Bomb后端云

                                                     用简单的代码 展示代码的魅力 Bmob 是后端云 全方位一体化的后端服务平台 提供可靠的 Server ...

  7. 替代学习物联网-云服务-02阿里云MQTT

     1.支付宝登录,进入物联网平台 https://iot.console.aliyun.com/product  2.新建产品  3.添加设备 4.设备连接参数  5.连接到阿里云

  8. php excel导出列超过26个字母处理

    /** * String from columnindex * * @param int $pColumnIndex Column index (base 0 !!!) * @return strin ...

  9. 策略模式demo

    /** StrategyContext. */ public class StrategyContext { private Strategy strategy; // 传入的是Strategy的实现 ...

  10. EF存储过程

    select * from Goods --创建存储过程create proc sp_Show( @index int, --当前页 @size int, --每页大小 @totalcount int ...