import java.util.Scanner;
class Role {
int health;
int attack;
public Role() {}
public void setNumber(int health,int attack) {
this.health=health;
this.attack=attack;
}
public void changeHealth(int attacknum) {
this.health-=attacknum;
}
public int getHealth() {
return health;
}
public int getAttack() {
return attack;
}
}
class Player {
Role roles[]=new Role[8];
void init() {
Role hero=new Role();
hero.setNumber(30, 0);
roles[0]=hero;
}
public void summon(int postion,int health,int attack) {
Role temp=new Role();
temp.setNumber(health, attack);
for(int i=roles.length-1;i>=postion;i--) {
if(roles[i]==null) {
continue;
}
roles[i+1]=roles[i];
}
roles[postion]=temp;
}
public boolean checkHeroIsDeadth() {
if(roles[0].health<=0) {
return true;
}
return false;
}
public void updateRetinuePostion() {
for(int i=1;i<roles.length;i++) {
if(roles[i]==null) {
continue;
}
if(roles[i].health<=0) {
for(int j=i;j+1<roles.length;j++) {
roles[j]=roles[j+1];
if(roles[j]==null) {
break;
}
}
}
}
}
public void attack(int attacker,int defender,Player another) {
int attacknum=another.roles[defender].getAttack();
roles[attacker].changeHealth(attacknum);
attacknum=roles[attacker].getAttack();
another.roles[defender].changeHealth(attacknum);
}
public void retinueNumHealth() {
int num=0;
int[] hvalue=new int[8];
for(int i=1;i<roles.length;i++) {
if(roles[i]!=null&&roles[i].health>0) {
hvalue[num]=roles[i].health;
num++;
}
}
System.out.print(num+ " ");
for(int i=0;i<num;i++) {
if(i!=num-1) {
System.out.print(hvalue[i]+ " ");
}
else {
System.out.print(hvalue[i]);
}
}
System.out.println();
}
}
public class Main {
static int people=0;
public static int getPeople() {
people=(people+1)%2;
return people;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
Player A=new Player();
A.init();
Player B=new Player();
B.init();
Player game[]=new Player[2];
game[0]=A;
game[1]=B;
int result=0;
sc.nextLine();
boolean flag=false;
for(int i=0;i<n;i++) {
String action=new String();
action=sc.nextLine();
String temp[]=action.split("\\s+");
if(temp[0].equals("end")) {
people=getPeople();
continue;
}
if(temp[0].equals("summon")) {
int postion=Integer.valueOf(temp[1]);
int health=Integer.valueOf(temp[3]);
int attack=Integer.valueOf(temp[2]);
game[people].summon(postion, health, attack);
continue;
}
if(temp[0].equals("attack")) {
int attacker=Integer.valueOf(temp[1]);
int defender=Integer.valueOf(temp[2]);
game[people].attack(attacker, defender, game[(people+1)%2]);
if(attacker==0||defender==0) {
if(game[0].checkHeroIsDeadth()) {
result=-1;
flag=true;
break;
}
if(game[1].checkHeroIsDeadth()) {
result=1;
flag=true;
break;
}
}
game[0].updateRetinuePostion();
game[1].updateRetinuePostion();
}
}
if(flag==false) {
result=0;
}
System.out.println(result);
System.out.println(game[0].roles[0].health);
game[0].retinueNumHealth();
System.out.println(game[1].roles[0].health);
game[1].retinueNumHealth();
sc.close();
}
}
在这里插入代码片
实在抱歉测试只有90分,还没有找到问题,有小伙伴找到的话,欢迎评论区指教!