CCF CSP201609-3炉石传说(c++100)
CCF CSP201609-3炉石传说
简单模拟
#include<iostream> #include<string> using namespace std; struct Hero{ int attack,health; }A[8],B[7]; int main(){ A[0].attack = B[0].attack = 0; A[0].health = B[0].health = 30; int n; cin>>n; bool flag = true;//true标志玩家A,false标志玩家B int winner = 0,summon1 = 0, summon2 = 0; for(int i = 0; i < n; i++){ string s; cin>>s; if(s == "summon"){ int position,attack,health; cin>>position>>attack>>health; if(flag){ for(int j = 6; j >= position; j--){ A[j+1] = A[j]; } A[position].attack = attack; A[position].health = health; summon1++; }else{ for(int j = 6; j >= position; j--){ B[j+1] = B[j]; } B[position].attack = attack; B[position].health = health; summon2++; } } else if(s == "attack"){ int attacker,defender; cin>>attacker>>defender; if(flag){ A[attacker].health -= B[defender].attack; B[defender].health -= A[attacker].attack; if(A[attacker].health <= 0 && attacker != 0){ for(int j = attacker; j < 7; j++){ A[j] = A[j+1]; } A[7].attack = A[7].health = 0; summon1--; } if(B[defender].health <= 0 && defender != 0){ for(int j = defender; j < 7; j++){ B[j] = B[j+1]; } B[7].attack = B[7].health = 0; summon2--; } } else{ B[attacker].health -= A[defender].attack; A[defender].health -= B[attacker].attack; if(A[defender].health <= 0 && defender != 0){ for(int j = defender; j < 7; j++){ A[j] = A[j+1]; } A[7].attack = A[7].health = 0; summon1--; } if(B[attacker].health <= 0 && attacker != 0){ for(int j = attacker; j < 7; j++){ B[j] = B[j+1]; } B[7].attack = B[7].health = 0; summon2--; } } if(A[0].health <= 0) { winner = -1; break; } if(B[0].health <= 0) { winner = 1; break; } } else if(s == "end"){ flag = !flag; } // for(int j = 1; j <= 7; j++){ // cout<<A[j].health<<":"<<A[j].attack<<" "; // } // cout<<endl; // for(int j = 1; j <= 7; j++){ // cout<<B[j].health<<":"<<B[j].attack<<" "; // } // cout<<endl; } cout<<winner<<endl; cout<<A[0].health<<endl; cout<<summon1; for(int i = 1; i<= 7; i++){ if(A[i].health > 0) { cout<<" "<<A[i].health; } } cout<<endl; cout<<B[0].health<<endl; cout<<summon2; for(int i = 1; i<= 7; i++){ if(B[i].health > 0) cout<<" "<<B[i].health; } cout<<endl; return 0; }