CCF_炉石传说
来源:互联网 发布:办公软件下载官方网站 编辑:程序博客网 时间:2024/06/10 00:03
该编程题主要考察的是数据结构的使用,一个好的数据结构处理问题来得心应手
我是通过利用C++中原有的list数据结构(大体上相当于一个双向链表)解决该问题的,其中list的每个元素需保存角色和随从的position、attack、health。
#include<iostream>#include<string>#include<list>using namespace std;class AI{public: int position; int attack; int health; AI(int p,int a,int h){ position=p; attack=a; health=h; }};typedef list<AI> LISTAI;int main(){ int n; cin>>n; LISTAI pet_one,pet_two; pet_one.push_front(AI(0,0,30)); pet_two.push_front(AI(0,0,30)); LISTAI::iterator ite; string action; LISTAI *pet_att=&pet_one; LISTAI *pet_def=&pet_two; for(int i=0;i<n;i++){ cin>>action; if(action=="summon"){ int p,a,h,tag=0; cin>>p>>a>>h; AI temp(p,a,h); for(ite=pet_att->begin();ite!=pet_att->end();++ite){ if(ite->position==p){ pet_att->insert(ite,temp); tag=1; while(ite!=pet_att->end()){ ite->position++; ite++; } break; } } if(tag!=1) pet_att->push_back(temp); } else if(action=="attack"){ int att,def; cin>>att>>def; LISTAI::iterator ite_att,ite_def; for(ite_att=pet_att->begin();ite_att!=pet_att->end();++ite_att) if(ite_att->position==att) break; for(ite_def=pet_def->begin();ite_def!=pet_def->end();++ite_def) if(ite_def->position==def) break; ite_att->health-=ite_def->attack; ite_def->health-=ite_att->attack; if(ite_att->health<=0){ ite_att=pet_att->erase(ite_att); for(;ite_att!=pet_att->end();++ite_att) ite_att->position--; } if(ite_def->position!=0&&ite_def->health<=0){ ite_def=pet_def->erase(ite_def); for(;ite_def!=pet_def->end();++ite_def) ite_def->position--; } else if(ite_def->position==0&&ite_def->health<=0){ break; } } else if(action=="end"){ LISTAI *pp=pet_att; pet_att=pet_def; pet_def=pp; } } if(pet_one.begin()->health<=0) cout<<-1<<endl; else if(pet_two.begin()->health<=0) cout<<1<<endl; else cout<<0<<endl; ite=pet_one.begin(); cout<<ite->health<<endl; ite++; cout<<pet_one.size()-1; for(;ite!=pet_one.end();++ite){ cout<<" "<<ite->health; } cout<<endl; ite=pet_two.begin(); cout<<ite->health<<endl; ite++; cout<<pet_two.size()-1; for(;ite!=pet_two.end();++ite){ cout<<" "<<ite->health; } cout<<endl; return 0;}
阅读全文
0 0
- CCF_炉石传说
- 炉石传说
- CCF 炉石传说
- CCF炉石传说
- ccf 炉石传说
- CCF-炉石传说
- CCF-炉石传说
- CCF炉石传说
- 炉石传说辅助
- CCF炉石传说
- CCF-炉石传说
- CCF 炉石传说
- ccf炉石传说
- 炉石传说
- ccf 炉石传说
- ccf 炉石传说
- 炉石传说_80
- 炉石传说卡
- 在已有工程中实现微信图片压缩
- tomcat启动成功之后无法访问项目主页解决办法
- 一种基于javascript的索引建立
- android 页面消息传递,观察者模式处理,打造纯粹的消息传递。
- 亚马逊AWS EC212个月免费计划及连接问题
- CCF_炉石传说
- [LintCode]223.回文链表
- Pandas入门—Series和DataFrame
- 背包问题总结
- 剑指offer_二叉搜索树的第k个节点
- Windows进程父子关系小实验
- 一分钟了解"英语表达:算法复杂度高低/速度快慢"
- js控制输入框取得焦点时另一内容显示/隐藏
- 服务器分批次上传:Argument list too long 错误