蓝桥杯-小蓝的图书馆

问题描述

小蓝是一个热爱阅读的年轻人,他有一个小型图书馆。为了能够管理他的书籍库存,他需要一个程序来记录图书的信息并执行两种操作:添加图书 addadd 和查找作者 findfind。

初始小蓝没有书,给出 n个操作。add 操作给出两个字符串 bookname,author,表示添加的图书图书名和作者;find 操作给出一个字符串 author,你需要输出小蓝的图书馆里这个 author有多少本图书。

输入格式

第一行一个整数 n,表示有 n 个操作。

之后 n 行,给出操作及后面的参数,如题所述。

给出的字符串长度 len 不超过 10。

输出格式

对每一个 find操作,你需要输出这个作者在小蓝的图书馆有多少本书,注意是书的数量,不是不同书的数量,同时不同作者可能出现同名的书。

样例输入

7
find author1
add book1 author1
find author1
add book1 author1
find author1
add book1 author2
find author2

样例输出

0
1
2
1

评测数据规模

1≤n≤1000,1≤len≤101≤n≤1000,1≤len≤10。

运行限制

语言 最大运行时间 最大运行内存
C++ 1s 256M
C 1s 256M
Java 2s 256M
Python3 3s 256M
PyPy3 3s 256M
Go 3s 256M
JavaScript 3s 256M
#include 
#include
using namespace std;

maplib;

int main()
{
  int n;
  cin>>n;
  for(int i=0;i>operation;
    if(operation=="add"){
      string book,author;
      cin>>book>>author;
      lib[author]++;
    }
    else if(operation=="find"){
      string author;
      cin>>author;
      cout<

你可能感兴趣的:(算法,c++,蓝桥杯)