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. 【Kafka】

    KafkaProducer Kafka消息发布客户端. 线程安全,跨线程共享单个生产者实例通常比拥有多个实例的速度更快. 例子,使用生产者发送包含序列号的字符串作为键/值对的记录: Propertie ...

  2. Spring Framework 5.0 新特性

    Spring Framework 5.0是在Spring Framework 4.0之后将近四年内一次重大的升级. 在这个时间框架内,主要的发展之一就是Spring Boot项目的演变. Spring ...

  3. Linux修改hostname的几种方法

    修改hostname有几种方式 1:  hostname DB-Server                            --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改 ...

  4. Ubuntu下的终端多标签切换快捷键

    ubuntu下由于常在终端下工作,也同样需要在一个终端窗口下开启多个标签方便日常开发工作(vim党,尽量避免使用鼠标) 方法一: alt+1 alt+2 alt+3 方法二: ctrl + pageU ...

  5. mysql导出数据库和恢复数据库代码

    mysql导出数据库和备份数据库 用mysqldump 命令行 命令格式 mysqldump -u 用户名 -p  数据库名 > 数据库名.sql 范例: mysqldump -uroot -p ...

  6. RewriteMap(apache)

    最近在工作中发现一个陌生的语法,apache服务器站点rewrite配置文件里的,开始还以为是apache的一种新语法,以这个词网上搜索,没搜到相关文章,跟老同事请教了一下,说这个是RewriteMa ...

  7. js 将一大段时间均分为很多个小时间段

    最近写项目,遇到一个将选中时间段平均分割为若干小段,然后根据小段时间在数据库查询求均值的问题,后台大哥犯懒,非说后台做不了,让我分好传给他ヾ(. ̄□ ̄)ツ゜゜゜好气呦,但还要保持微笑,我就是这么懂礼貌 ...

  8. iOS10适配相关

    2016年9月7日,苹果发布iOS 10.2016年9月14日,全新的操作系统iOS 10将正式上线. 作为开发者,如何适配iOS10呢? 1.Notification(通知) 自从Notificat ...

  9. App 监控、推广

    一.监控 酷传  http://www.kuchuan.com/ 应用雷达  http://www.ann9.com/ AppAnnie https://www.appannie.com/cn/ ap ...

  10. win10 UWP 圆形等待

    看到一个圆形好像微软ProgressRing 我们可以用自定义控件 按ctrl+shift+a 用户控件 我们可以用Rectangle做圆形边 只要Rectangle RadiusX>0圆角 因 ...