#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int DRAGON=0,NINJIA=1,ICEMAN=2,LION=3,WOLF=4;
const int now_order[2][5]={{2,3,4,1,0},{3,0,1,2,4}};
const char* s[2]={"red","blue"};
const char* ss[5]={"dragon","ninja","iceman","lion","wolf"};
const char* sss[3]={"sword","bomb","arrow"};
int need[5],order[2],number[2],_attack[5],worriors_temp[2],now_time,city_sum,total[2],arrow_attack,loyalty_minus;
bool head_num[2],game_over,last_color[2];
class sword
{
private:
int force;
public:
sword(int x):force(x) {}
void used() {force=force*0.8;}
bool is_deserted() {return (force==0);}
int get_force() {return force;}
};
class arrow
{
private:
int used_times;
int force;
public:
arrow(int x,int y):used_times(x),force(y) {}
void used() {used_times--;}
bool is_deserted() {return (used_times==0);}
int get_force() {return force;}
int get_used_time() {return used_times;}
};
class worriors
{
public:
worriors(int,int,int);
~worriors()
{
if (_sword!=NULL) delete _sword;
if (_arrow!=NULL) delete _arrow;
}
void get_hp(int a) {hp+=a;}
virtual void happy(int) {}
virtual void change_morale(int) {}
virtual bool will_escape() {return false;}
virtual void minus_loyalty() {}
friend class city;
protected:
int type;
int id;
int hp;
int color;
int attack;
sword* _sword;
arrow* _arrow;
bool has_bomb;
};
class dragon: public worriors
{
private:
double morale;
public:
dragon(int _color,int _id,int _type):worriors(_color,_id,_type)
{
morale=(double)total[_color]/(double)need[0];
printf("Its morale is %.2lf\n",morale);
}
void happy(int _id)
{
if (morale>0.8)
printf("%.3d:40 %s dragon %d yelled in city %d\n",now_time,s[color],id,_id);
}
void change_morale(int a) {morale+=((a==1)?0.2:-0.2);}
};
class lion: public worriors
{
private:
int loyalty;
public:
lion(int _color,int _id,int _type):worriors(_color,_id,_type)
{
loyalty=total[_color];
printf("Its loyalty is %d\n",loyalty);
}
bool will_escape() {return (loyalty<=0);}
void minus_loyalty() {loyalty-=loyalty_minus;}
};
class city
{
private:
int id;
int color;
int hp;
int last_beat_win;
int just_beat_win;
public:
worriors* data[2];
~city()
{
for (int i=0;i<=1;i++)
if (data[i]!=NULL)
delete data[i];
}
void creat(int);
void input_hp() {hp+=10;};
void output_hp();
void beat_win(int,int,int);
void beat();
void draw(int);
void go(city*,int);
bool reach_headquater(int);
void print_last_go();
void escape(int);
void use_bomb();
void tell_weapon(int);
void shoot_arrow(city*,int);
int get_attack(int);
int get_just_beat_win() {return just_beat_win;}
void bang(int);
} citys[22];
worriors::worriors(int _color,int _id,int _type)
{
printf("%.3d:00 %s %s %d born\n",now_time,s[_color],ss[_type],_id);
total[_color]-=need[_type];
id=_id;
color=_color;
type=_type;
hp=need[_type];
attack=_attack[_type];
_sword=NULL;
has_bomb=false;
_arrow=NULL;
switch(_type)
{
case DRAGON:case ICEMAN:
switch (id%3)
{
case 0:
if ((int)(attack*0.2)!=0)
_sword=new sword(attack*0.2);
break;
case 1:
has_bomb=true;
break;
default:
_arrow=new arrow(3,arrow_attack);
}
break;
case NINJIA:
switch(id%3)
{
case 0:
if ((int)(attack*0.2)!=0)
_sword=new sword(attack*0.2);
has_bomb=true;
break;
case 1:
has_bomb=true;
_arrow=new arrow(3,arrow_attack);
break;
default:
_arrow=new arrow(3,arrow_attack);
if ((int)(attack*0.2)!=0)
_sword=new sword(attack*0.2);
}
break;
default:;
}
}
void city::creat(int _id)
{
last_beat_win=just_beat_win=color=-1;
id=_id;
hp=0;
data[0]=data[1]=NULL;
}
void city::beat_win(int _color,int left_hp,int y)
{
if (data[_color]->type==WOLF)
{
if (data[_color]->_sword==NULL && data[1-_color]->_sword!=NULL)
data[_color]->_sword=new sword(data[1-_color]->_sword->get_force());
if (!data[_color]->has_bomb && data[1-_color]->has_bomb)
data[_color]->has_bomb=true;
if (data[_color]->_arrow==NULL && data[1-_color]->_arrow!=NULL)
data[_color]->_arrow=new arrow(data[1-_color]->_arrow->get_used_time(),data[1-_color]->_arrow->get_force());
}
delete data[1-_color];
data[1-_color]=NULL;
if (y==1)
{
data[_color]->change_morale(1);
data[_color]->happy(id);
}
data[_color]->hp+=left_hp;
printf("%.3d:40 %s %s %d earned %d elements for his headquarter\n",now_time,
s[_color],ss[data[_color]->type],data[_color]->id,hp);
worriors_temp[_color]+=hp;
hp=0;
just_beat_win=_color;
if (color!=_color && last_beat_win==_color)
{
color=_color;
printf("%.3d:40 %s flag raised in city %d\n",now_time,s[_color],id);
}
last_beat_win=_color;
}
void city::output_hp()
{
int turn=-1;
if (data[0]!=NULL && data[1]==NULL) turn=0;
if (data[1]!=NULL && data[0]==NULL) turn=1;
if (turn!=-1)
{
printf("%.3d:30 %s %s %d earned %d elements for his headquarter\n",now_time,s[turn],ss[data[turn]->type],data[turn]->id,hp);
total[turn]+=hp;
hp=0;
}
}
void city::beat()
{
int turn=1,left_hp=0,add_attack;
just_beat_win=-1;
if (data[0]==NULL)
{
if (data[1]!=NULL && data[1]->hp==0)
{
delete data[1];
data[1]=NULL;
}
return;
}
if (data[1]==NULL)
{
if (data[0]->hp==0)
{
delete data[0];
data[0]=NULL;
}
return;
}
if (color==0 || (color==-1 && id%2==1)) turn=0;
if (data[turn]->hp==0 && data[1-turn]->hp==0)
{
delete data[0];
delete data[1];
data[0]=data[1]=NULL;
return;
}
if (data[turn]->hp==0)
{
beat_win(1-turn,0,0);
return;
}
if (data[1-turn]->hp==0)
{
beat_win(turn,0,1);
return;
}
printf("%.3d:40 %s %s %d ",now_time,s[turn],ss[data[turn]->type],data[turn]->id);
printf("attacked %s %s %d in city %d with %d elements and force %d\n",s[1-turn],ss[data[1-turn]->type],data[1-turn]->id,id,data[turn]->hp,data[turn]->attack);
if (data[1-turn]->type==LION)
left_hp=data[1-turn]->hp;
add_attack=get_attack(turn);
data[1-turn]->hp-=data[turn]->attack+add_attack;
if (data[1-turn]->hp<=0)
{
printf("%.3d:40 %s %s %d was killed in city %d\n",now_time,s[data[1-turn]->color],ss[data[1-turn]->type],data[1-turn]->id,id);
beat_win(turn,left_hp,1);
return;
}
if (data[1-turn]->type!=NINJIA)
{
add_attack=get_attack(1-turn);
printf("%.3d:40 %s %s %d fought back against %s %s %d in city %d\n",now_time,s[1-turn],
ss[data[1-turn]->type],data[1-turn]->id,s[turn],ss[data[turn]->type],data[turn]->id,id);
if (data[turn]->type==LION)
left_hp=data[turn]->hp;
else left_hp=0;
data[turn]->hp-=data[1-turn]->attack/2+add_attack;
if (data[turn]->hp<=0)
{
printf("%.3d:40 %s %s %d was killed in city %d\n",now_time,s[data[turn]->color],ss[data[turn]->type],
data[turn]->id,id);
beat_win(1-turn,left_hp,0);
return;
}
}
draw(turn);
}
int city::get_attack(int _color)
{
int add_attack=0;
if (data[_color]->_sword!=NULL)
{
add_attack=data[_color]->_sword->get_force();
data[_color]->_sword->used();
if (data[_color]->_sword->is_deserted())
{
delete data[_color]->_sword;
data[_color]->_sword=NULL;
}
}
return add_attack;
}
void city::draw(int turn)
{
data[0]->minus_loyalty();
data[1]->minus_loyalty();
data[turn]->change_morale(-1);
data[turn]->happy(id);
last_beat_win=-1;
}
void city::go(city* next,int _color)
{
data[_color]=next->data[_color];
if (data[_color]!=NULL && data[_color]->type==ICEMAN)
{
if ((_color==0 && id%2==0) || (_color==1 && (city_sum-id)%2==1))
{
data[_color]->hp-=9;
if (data[_color]->hp<=0) data[_color]->hp=1;
data[_color]->attack+=20;
}
}
}
bool city::reach_headquater(int _color)
{
if (!last_color[_color]) return false;
printf("%.3d:10 %s %s %d reached %s headquarter with %d elements and force %d\n",now_time,
没有合适的资源?快使用搜索试试~ 我知道了~
OUC Online Judge部分题目答案(C++)
共89个文件
txt:89个
需积分: 19 0 下载量 196 浏览量
2023-03-16
16:24:28
上传
评论 2
收藏 66KB ZIP 举报
温馨提示
OUC OJ平台的题库部分习题答案,C++版本,共89道题,几乎都是通过平台测试的,少量未通过的有标注。 压缩包内文件为txt文件,文件名为对应的题目名,部分是在网上搜索借鉴的,部分为作者原创。 warning:本文件仅作参考借鉴使用。 欢迎私信补充题库。
资源推荐
资源详情
资源评论
收起资源包目录
代码整理.zip (89个子文件)
代码整理
合并整数.txt 302B
priority queue练习题.txt 2KB
编程填空:数值计算.txt 845B
点评赛车.txt 379B
EXCEL排序(C++版).txt 2KB
热血格斗场.txt 826B
factorial_and_power.txt 305B
看上去像多态.txt 667B
运算符重载 填空题3.txt 1KB
填空题1.txt 435B
八进制小数.txt 416B
按距离排序.txt 1KB
拼接两个排好序的链表.txt 1009B
编程填空:输出学生信息.txt 572B
冷血格斗场.txt 721B
重点防护.txt 1KB
虚函数与多态 填空题3(题目好像是模板的).txt 895B
比较版本 (有问题版).txt 364B
魔兽世界一: 备战(自我改写版).txt 3KB
惊呆!Point竟然能这样输入输出.txt 460B
大整数的加减乘除(网上的 平台测试通过).txt 10KB
奇怪的类复制.txt 473B
Big & Base 封闭类问题.txt 433B
放苹果.txt 732B
魔兽世界二:装备(网上版).txt 5KB
魔兽世界二:装备(上题添写版).txt 4KB
编程填空:学生信息处理程序.txt 837B
别叫,这个大整数已经很简化了!.txt 2KB
Set.txt 644B
k进制数1的个数.txt 293B
岛屿周长.txt 527B
魔兽世界终极版.txt 14KB
奇数求和.txt 250B
复制构造函数 填空题一.txt 290B
凯撒密码.txt 189B
为啥 while(cin n) 能成立?.txt 333B
这是什么鬼delete.txt 321B
第N位数字.txt 583B
这个模板并不难.txt 863B
6174猜想.txt 788B
古代密码.txt 734B
EXCEL排序(C++缩减版).txt 1KB
矩阵乘法.txt 2KB
奇怪的输出.txt 523B
函数对象的过滤器.txt 1KB
白给的list排序.txt 409B
我自己的 ostream_iterator.txt 904B
倒过来输出.txt 487B
你真的搞清楚为啥 while(cin n) 能成立了吗?.txt 404B
日期计算.txt 777B
List.txt 880B
简单的foreach.txt 809B
怎么又是Fun和Do.txt 578B
运算符重载 填空题2.txt 424B
整数的个数.txt 318B
山寨版istream_iterator.txt 840B
排序,又见排序!.txt 1KB
不吉利日期.txt 401B
做游戏.txt 616B
魔兽世界一: 备战(网上版).txt 4KB
继承自string的MyString.txt 1KB
比较版本.txt 528B
简单的学生信息处理程序实现.txt 631B
全面的Mystring.txt 4KB
有序链表插入.txt 1KB
简单的Filter.txt 776B
看上去好坑的运算符重载.txt 489B
排队.txt 1KB
返回什么才好呢.txt 396B
填空题2.txt 293B
Fun和Do.txt 555B
虚函数与多态 填空题2.txt 537B
晶晶赴约会.txt 382B
多项式输出.txt 555B
基数排序的过程.txt 676B
三角形的面积.txt 387B
求函数值.txt 346B
数根.txt 501B
很难蒙混过关的CArray3d三维数组模板类.txt 2KB
实数的输出格式.txt 309B
扫雷计数.txt 1KB
复制构造函数 填空题二.txt 402B
大整数的加减乘除 (未经平台测试).txt 5KB
虚函数与多态 填空题1.txt 564B
编程填空:数据库内的学生信息.txt 2KB
运算符重载 填空题1.txt 517B
MyString.txt 1KB
有序链表插入(1).txt 2KB
计算对数.txt 1KB
共 89 条
- 1
资源评论
刚刚学习编程的小白
- 粉丝: 3
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功