ccf 201609-3 炉石传说
ccf 201609-3 炉石传说
还差30分,暂留
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 struct node{ 5 int health;//生命值 6 int attack;//攻击力 7 node(int health = 0,int attack = 0):health(health),attack(attack){ 8 } 9 }heros[2][8];//两个用户,最多有7个英雄 10 11 void move(int player,int p,int dir) 12 {//从 p 向后移动 13 int temp = p; 14 if(dir == 1){//向后移动 ,需向p位置插入 15 for(int i=7;i>p;i--) 16 { 17 heros[player][i].attack = heros[player][i-1].attack; 18 heros[player][i].health = heros[player][i-1].health; 19 } 20 }else if(dir == 0) 21 {///向前移动 ,需将p位置删除 22 for(int i=p;i<7;i++) 23 { 24 heros[player][i].attack = heros[player][i+1].attack; 25 heros[player][i].health = heros[player][i+1].health; 26 } 27 } 28 } 29 30 void summon(int player) 31 {//召唤随从 32 int p,a,h; 33 cin>>p>>a>>h; 34 if(heros[player][p].health != 0)//进行移动 35 { 36 move(player,p,1);//向后移动 37 } 38 heros[player][p].attack = a;heros[player][p].health = h; 39 } 40 41 void attack(int player) 42 { 43 int attacker,defender; 44 cin>>attacker>>defender; 45 int de = 1-player; 46 heros[de][defender].health -= heros[player][attacker].attack; 47 heros[player][attacker].health -= heros[de][defender].attack; 48 if(heros[de][defender].health<=0) 49 { 50 move(de,defender,0); 51 } 52 if(heros[player][attacker].health<=0) 53 { 54 move(player,attacker,0); 55 } 56 } 57 58 int main() 59 { 60 int n; 61 cin>>n; 62 char str[10]; 63 //为两方设置英雄 64 heros[0][0].attack = 0;heros[0][0].health = 30; 65 heros[1][0].attack = 0;heros[1][0].health = 30; 66 67 int player = 0; 68 while(n--){ 69 cin>>str;//读入操作 70 if(strcmp(str,"summon") == 0) //召唤随从 71 { 72 summon(player); 73 } 74 else if(strcmp(str,"attack") == 0) //发动攻击 75 { 76 attack(player); 77 } 78 else if(strcmp(str,"end") == 0)//操作结束 79 { 80 ///换玩家 81 player = 1-player; 82 } 83 84 if(heros[0][0].health<=0 || heros[1][0].health<=0) break; 85 } 86 ///打印结果: 87 bool flag1 = false,flag2 = false; 88 if(heros[0][0].health>0) flag1 = true; 89 if(heros[1][0].health>0) flag2 = true; 90 if(flag1 && !flag2) 91 {//先手玩家胜 92 cout<<1<<endl; 93 }else if(!flag1 && flag2) 94 {//后手玩家胜 95 cout<<-1<<endl; 96 }else{//游戏还没结束 97 cout<<0<<endl; 98 } 99 cout<<heros[0][0].health<<endl; 100 int num = 0; 101 for(int i=1;i<=7;i++) 102 { 103 if(heros[0][i].health>0) num++; 104 } 105 cout<<num; 106 for(int i=1;i<=7;i++) 107 { 108 if(heros[0][i].health>0) cout<<" "<<heros[0][i].health; 109 } 110 cout<<endl; 111 cout<<heros[1][0].health<<endl; 112 num = 0; 113 for(int i=1;i<=7;i++) 114 { 115 if(heros[1][i].health>0) num++; 116 } 117 cout<<num; 118 for(int i=1;i<=7;i++) 119 { 120 if(heros[1][i].health>0) cout<<" "<<heros[1][i].health; 121 } 122 cout<<endl; 123 124 return 0; 125 }