因为是今年大一重带的期末考试题,所以目前找不到电子版的题目,这里就不多描述了,如果重带学子之后复习的时候遇到了这题就直接看就行了
#include <bits/stdc++.h>
using namespace std;
//声明一个老鼠类
class mice
{
public:
int x;
int y;
int hp;
mice(int x,int y):x(x),y(y),hp(2){};//有参构造
};
int main()
{
int m,n;
cin>>m>>n;
vector<mice> v;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
char c;//画地图
cin>>c;
if(c=='#')//有老鼠,就直接将老鼠信息完善并推入数组里面
{
mice temp(i,j);
v.push_back(temp);
}
}
}
int num;
cin>>num;
for(int i=0;i<num;i++)
{
int x,y;
cin>>x>>y;
//因为考虑余波,因此以击打坐标为基础产生四个衍生坐标
int x1=x-1;
int x2=x+1;
int y1=y-1;
int y2=y+1;
//进行判定
for(vector<mice>::iterator it=v.begin();it!=v.end();it++)
{
if(it->x==x&&it->y==y) it->hp-=2;
else if(it->x==x1&&it->y==y) it->hp-=1;
else if(it->x==x2&&it->y==y) it->hp-=1;
else if(it->x==x&&it->y==y1) it->hp-=1;
else if(it->x==x&&it->y==y2) it->hp-=1;
}
}
int count1,count2;
for(vector<mice>::iterator it=v.begin();it!=v.end();it++)
{
if(it->hp>0) count1++;
if(it->hp==1) count2++;
}
cout<<v.size()-count1<<" "<<count2;
return 0;
}
本文详细描述了一个C++程序,涉及老鼠类的定义、构造函数以及在一个二维地图上执行击打操作后,统计剩余老鼠数量和生命值为1的老鼠数量。
493






