Problem E: 动物爱好者

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 882  Solved: 699
[Submit][Status][Web Board]

Description

某人是一个狂热的动物爱好者,豢养了大量的各种动物。现在请定义两个类:

1. Animal类:

(1)string name和int  num属性表示该种动物的名称和数量。

(2)无参构造函数。

(3)void setAnimal(string,int)方法,用于设置一个动物的相关属性。

(4)int getNum() const和string getName() const方法用于获得该动物的数量和名称。

(5)重载的赋值运算符=。

2. AnimalList类:

(1)Animal *animalList和int numOfAnimal属性,用于表示该人豢养的所有动物的列表以及动物的种类数。

(2)构造函数AnimalList(Animal *animals, int n)。

(3)重载的下标运算符[],int operator[](string name),用于返回参数name指定名称的动物的数量,当不存在这种动物时,返回-1。

Input

第一行M>0表示有M种动物,之后有M行,每行第一个字符串表示动物名称,第二个整数是该种动物的数量。

之后一个N>0表示有N个测试用的动物名称,之后又有N行,每行是一个动物名。

Output

输出共N行,格式见样例。

Sample Input

5
Dog 5
Bird 10
Cat 11
Duck 1
Sparrow 66
6
Dog
Bird
Cat
Duck
Sparrow
Bull

Sample Output

There are 5 Dogs.
There are 10 Birds.
There are 11 Cats.
There are 1 Ducks.
There are 66 Sparrows.
There is none Bull.

HINT

注意:不能使用STL。

#include <iostream>
#include <string>
#include <cmath>
#define null ""
using namespace std;
class Animal
{
friend class AnimalList;
public:
    string name;
    int num;
    Animal():name(s),num(n){}
    void setAnimal(string s,int n){name=s;num=n;}
    int getNum(){return num;}
    string getName() const
    {
        return name;
    }
    Animal &operator =(const Animal &p)
    {
        name=p.name;
        num=p.num;
        return *this;
    }
};
class AnimalList
{
friend class Animal;
public:
    Animal *cats;
    int numofcat;
    AnimalList(Animal *s,int n):cats(s),numofcat(n){}
    int operator [](const string s)
    {
        ;i<numofcat;i++)
            if(cats[i].name==s)
            return cats[i].num;
        ;
    }
};
int main()
{
    int cases;
    string name;
    int num;
    cin>>cases;
    Animal animals[cases];
    ; i < cases; i++)
    {
        cin>>name>>num;
        animals[i].setAnimal(name, num);
    }
    AnimalList animalList(animals, cases);

    cin>>cases;
    ; i < cases; i++)
    {
        cin>>name;
        )
            cout<<"There are "<<animalList[name]<<" "<<name<<"s."<<endl;
        else
            cout<<"There is none "<<name<<"."<<endl;
    }
    ;
}

Problem E: 动物爱好者的更多相关文章

  1. 实验12:Problem J: 动物爱好者

    #define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...

  2. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  3. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  4. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  5. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  6. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  7. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  8. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  9. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

随机推荐

  1. mxnet的训练过程——从python到C++

    mxnet的训练过程--从python到C++ mxnet(github-mxnet)的python接口相当完善,我们可以完全不看C++的代码就能直接训练模型,如果我们要学习它的C++的代码,从pyt ...

  2. JSP入门 导出文件

    1.图片校验码 <img  src="captcha.jpg"  /> web.xml配置 <servlet>      <servlet-name& ...

  3. 初识Hibernate之理解持久化类

         上一篇文章我们简单介绍了Hibernate相关的一些最基本的文件及其作用,并在最后完整的搭建了Hibernate的运行环境,成功的完成了与数据库的映射.但是至于其中的一些更加细节的地方并没有 ...

  4. Springboot 学习笔记 ①

    前言 之前一直在寻找Springboot的学习资料,终于得偿所愿...那么,先给自己定一个小目标 - 能够使用Springboot这套架构来搭建自己的服务. 准备阶段 1. 开发环境 开发环境其实还是 ...

  5. hdu1512 Monkey King(左偏树 + 并查集)

    Once in a forest, there lived N aggressive monkeys. At the beginning, they each does things in its o ...

  6. Python实战之Selenium自动化测试web登录

    #!/usr/bin/env python3 # -*- coding:utf-8 -*- from selenium import webdriver from selenium.webdriver ...

  7. Python实战之网络编程socket学习笔记及简单练习

    sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM,0) 参数一:地址簇 socket.AF_INET IPv4(默认) socket.AF_IN ...

  8. tesseract-ocr字库训练图文讲解

    第一步合成图片集 你需要把使用jTessBoxEditor工具把你的训练素材及多张图片合并成一张tif格式的图片集 第二步  生成box文件 运行tesseract命令,tesseract mjorc ...

  9. 自动化selenium开发

    一.开发环境搭建 1.Firefox浏览器 1.1 下载firefix并安装. 1.2 Firefox中打开"开始菜单“ -> ”开发者“ -> ”获取更多工具“ -> 搜 ...

  10. ionic构建APP--简单操作实现APP制作

    ionic--基于AngularJS的app框架 1安装ionic .HBuilder创建APP项目,导入ionic的css,js(fonts)文件. .导入ionic.css和ionic.bundl ...