本题题意很好读,看上去也不难写
写完运行才发现输出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. Ubuntu下CodeBlocks控制台程序中文显示乱码解决问题

    今天在CodeBlocks下折腾来半天,终于把中文乱码给解决了,其实很简单. 在环境设置里进行如下设置:把Terminal to launch console programs那个选项改成gnome- ...

  2. 记D365开发的最佳实践

    前端JS 不同的需求应该划分模块,以便日后修改,也是为了职责分离,模块分离,日后如果想分离到单独的JS文件里面也是比较方便: 对于公共的查询函数,应该做缓存,优先使用sessionStorage. 多 ...

  3. spring boot整合druid

    其实网上有很多例子可供参考,主要是在整合的过程中遇到了一些问题,方便记录下.另外例子可参考以下两个链接: https://www.jianshu.com/p/e3cd2e1c2b0c https:// ...

  4. taro+vue3模板-废弃

    一.初始化 1.Taro 基本安装并初始化项目 npx @tarojs/cli init WechatAppDemo 2.cd到新项目的文件夹 3.安装依赖:yarn 4.运行预览: yarn dev ...

  5. CH340N串口无法检测问题的解决

    问题原因: type-C有好几种类型,其中包括能传输数据的,也有不能传输数据.只能供电的.(本质差别就是引脚数目不同) 问题解决:只要将原来的type-C转USB的充电线换成数据线,电脑就能识别CH3 ...

  6. 打包Assetbundle

    using UnityEngine;using System.Collections;using UnityEditor;/// <summary>/// 脚本位置:Editor文件夹下/ ...

  7. Java基础——二维数组

    package com.zhao.demo; public class Demo08 { public static void main(String[] args) { //二维数组 int[][] ...

  8. WinExec("D:\\MY_tool\\APPLICATION\\calc.exe", SW_SHOW);

    1 #pragma comment(lib,"shell32.lib")2 3 4 ShellExecute(NULL, NULL,"calc.exe", NU ...

  9. 2020-2021第一学期2024"DCDD"小组第十周讨论

    2020-2021第一学期"DCDD"第十周讨论 小组名称:DCDD 小组成员:20202403孟凡斌.20202411陈书桓.20202416刘铭睿.20202420黄椿淇 照例 ...

  10. WSL2与ensp的40故障

    在使用ensp做radius认证的时候看到了Linux平台的freeradius认证服务器,于是使用了Windows平台的sub system: WSL2,按照网上的教程安装,并且安装了docker ...