您的位置:首页 > 其它

ccf 201609-3 炉石传说

2017-08-22 14:43 323 查看
用vector的容器操作会更方便

#include<iostream>
#include<string>
using namespace std;
class servert {
public:
int h, a;
servert(int x, int y) { h = x; a = y; }
servert() { h = 0; a = 0; }

};
servert S[9][2];
void join(int f) {
int a, b, c;
cin >> a >> c >> b;
for (int i = 7; i>a; --i)
S[i][f] = S[i - 1][f];
S[a][f] = servert(b, c);
}
void ov(int f, int index) {
if (!index) { return; }
for (int i = index; i<7; ++i)
S[i][f] = S[i + 1][f];
S[7][f].h = 0;
}
void attack(int f, int d) {
int a, b;
cin >> a >> b;
int f1 = 0, f2 = 0;
if (S[a][f].a >= S[b][d].h) f1 = 1;
S[b][d].h -= S[a][f].a;
if (S[b][d].a >= S[a][f].h) f2 = 1;
S[a][f].h -= S[b][d].a;
if (f1) ov(d, b);
if (f2) ov(f, a);
}
void pp(int f) {
int nu = 0;
for (int i = 1; i <= 7; ++i)
if (S[i][f].h) ++nu;
else break;
cout << nu;
for (int i = 1; i <= nu; ++i)
cout << " " << S[i][f].h;
cout << endl;
}
int main()
{
S[0][0].h = S[0][1].h = 30;
S[0][0].a=S[0][1].a=0;
int n;
cin >> n;
string str;
int a = 0, b = 1;
while (n--) {
cin >> str;
if (str == "summon") join(a);
else if (str == "attack") attack(a, b);
else swap(a, b);
}
if (S[0][1].h<=0) cout << 1 << endl;
else if (S[0][0].h<=0) cout << -1 << endl;
else cout << 0 << endl;
cout << S[0][0].h << endl;
pp(0);
cout << S[0][1].h << endl;
pp(1);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: