Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.2 kB
2
Indexable
Never
package H2118;

import java.util.LinkedList;

class UserSolution {
	LinkedList<Person> list;
	
	public void init() {
		list = new LinkedList<Person>();

	}

	public void hire(int mID, int mTeam, int mScore) {
		list.add(new Person(mID, mTeam, mScore));
		
	}

	public void fire(int mID) {
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getpID() == mID) {
				list.remove(i);
				break;
			}
		}
	}

	public void updateSoldier(int mID, int mScore) {
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getpID() == mID) {
				list.get(i).setpScore(mScore);
				break;
			}
		}
		
	}

	public void updateTeam(int mTeam, int mChangeScore) {
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getpTeam() == mTeam) {
				if (list.get(i).getpScore() + mChangeScore > 5) {
					list.get(i).setpScore(5);
				} else if (list.get(i).getpScore() + mChangeScore < 1) {
					list.get(i).setpScore(1);
				} else {
					list.get(i).setpScore(
							list.get(i).getpScore() + mChangeScore);
				}
			}
		}
	}

	public int bestSoldier(int mTeam) {
		int best = Integer.MIN_VALUE;
		int id = 0;
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getpTeam() == mTeam) {
				if (list.get(i).getpScore() > best) {
					best = list.get(i).getpScore();
					id = list.get(i).getpID();
				}
				if (list.get(i).getpScore() == best
						&& list.get(i).getpID() > id) {
					id = list.get(i).getpID();
				}
			}
		}
		return id;
	}
}

class Person {
	int pID, pTeam, pScore;

	public int getpID() {
		return pID;
	}

	public void setpID(int pID) {
		this.pID = pID;
	}

	public int getpTeam() {
		return pTeam;
	}

	public void setpTeam(int pTeam) {
		this.pTeam = pTeam;
	}

	public int getpScore() {
		return pScore;
	}

	public void setpScore(int pScore) {
		this.pScore = pScore;
	}

	/**
	 * @param pID
	 * @param pTeam
	 * @param pScore
	 */
	public Person(int pID, int pTeam, int pScore) {
		super();
		this.pID = pID;
		this.pTeam = pTeam;
		this.pScore = pScore;
	}

	/**
	 * 
	 */
	public Person() {
	}

}
Leave a Comment