首页 > 分享 > 动物收容所领养系统设计

动物收容所领养系统设计

猫狗收容所

最新推荐文章于 2023-11-23 10:22:37 发布

原创 于 2016-10-23 11:54:56 发布 · 751 阅读

· 0

· 0 ·

CC 4.0 BY-SA版权

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

题目描述

        有家动物收容所只收留猫和狗,但有特殊的收养规则,收养人有两种收养方式,第一种为直接收养所有动物中最早进入收容所的,第二种为选择收养的动物类型(猫或狗),并收养该种动物中最早进入收容所的。

       给定一个操作序列int[][2] ope(C++中为vector<vector<int>>)代表所有事件。若第一个元素为1,则代表有动物进入收容所,第二个元素为动物的编号,正数代表狗,负数代表猫;若第一个元素为2,则代表有人收养动物,第二个元素若为0,则采取第一种收养方式,若为1,则指定收养狗,若为-1则指定收养猫。请按顺序返回收养的序列。若出现不合法的操作,即没有可以符合领养要求的动物,则将这次领养操作忽略。

测试样例:

[[1,1],[1,-1],[2,0],[2,-1]]

返回:[1,-1]

-------------------------------------------------------------------------------------

class CatDogAsylum {

public:

vector<int> asylum(vector<vector<int> > ope) {

vector<int> res;

deque<int> adopt;

for (decltype(ope.size()) i=0; i<ope.size(); ++i){

if (ope[i][0] == 1){

adopt.push_back(ope[i][1]);

} else if (ope[i][0] == 2){

if (ope[i][1] == 0){

if (!adopt.empty()){

res.push_back(adopt.front());

adopt.pop_front();

}else

continue;

}else if (ope[i][1] == 1){

if (adopt.empty())

continue;

deque<int>::iterator iter;

for (iter=adopt.begin(); iter!=adopt.end(); ++iter){

if (*iter > 0){

res.push_back(*iter);

adopt.erase(iter);

break;

}

}

} else if (ope[i][1] == -1){

if (adopt.empty())

continue;

deque<int>::iterator iter;

for (iter=adopt.begin(); iter!=adopt.end(); ++iter){

if (*iter < 0){

res.push_back(*iter);

adopt.erase(iter);

break;

}

}

}

}

}

return res;

}

};

cpp

运行

相关知识

动物收容所领养系统设计
宠爱有家·动物收容所收容所领养条件
动物收容所领养策略
动物领养系统设计与实现任务书
动物收容所宠物护理模拟手游最新版
“宠物领养系统网站设计.pdf:作品选题及开发环境概述”
基于Springboot+Vue框架的宠物领养管理系统设计与实现 毕业设计开题报告
在宠物店与动物收容所,领养狗狗的利与弊
动物收容所模拟器
宠物领养系统网站设计.pdf

网址: 动物收容所领养系统设计 https://m.mcbbbk.com/newsview1267369.html

所属分类:萌宠日常
上一篇: 静安宠物狗猫收养收容救助站
下一篇: 「图」宝山区杨行镇宠物收容中心基