Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.util.stream.Collectors;
- public class SomeClassNameHere {
- //this Writer is fast! comparedTo sout, souf etc...
- static class OutputWriter {
- private final PrintWriter writer;
- OutputWriter() {
- writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
- }
- void print(Object... objects) {
- for (int i = 0; i < objects.length; i++) {
- if (i != 0)
- writer.print(' ');
- writer.print(objects[i]);
- }
- }
- void printLine(Object... objects) {
- print(objects);
- writer.println();
- }
- void close() {
- writer.close();
- }
- }
- private static void fakeInput() {
- String input = "FAKE_INPUT_HERE";
- System.setIn(new ByteArrayInputStream(input.getBytes()));
- }
- public static void main(String[] args) throws IOException {
- fakeInput();
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //faster than scanner!
- OutputWriter out = new OutputWriter(); // much faster than System.out.print(f/ln)
- init();
- run(br, out); //need to be send as parameters
- out.close(); //close writer
- }
- private static void init() {
- // Data Structures Initialization here
- }
- //run method
- private static void run(BufferedReader br, OutputWriter out) throws IOException {
- String[] command = br.readLine().split(" ");
- while (!Objects.equals(command[0], "end")) {
- switch (command[0]) {
- case "add":
- ..
- handleAddCommand(.., out);
- break;
- case "find":
- ..
- handleFindCommand(.., out);
- break;
- case "next":
- ..
- handleNextCommand(.., out);
- break;
- ...
- default:
- break;
- }
- command = br.readLine().split(" ");
- }
- }
- private static void handleNextCommand(.., OutputWriter out) {
- //much faster than souf!!! use StringBuilder!
- StringBuilder builder = new StringBuilder();
- builder.append(..);
- builder.append("..");
- ..
- builder.deleteCharAt(builder.length() - 1);
- ..
- out.printLine(builder);
- }
- private static void handleFindCommand( .., OutputWriter out) {
- StringBuilder toPrint = new StringBuilder();
- toPrint.append("..").append(typeToFind).append("..");
- ..
- out.print(toPrint);
- ..
- }
- private static void handleAddCommand(.., OutputWriter out) {
- StringBuilder toPrint = new StringBuilder();
- ..
- out.printLine(toPrint);
- }
- private static class Player implements Comparable<Player>{
- private String name;
- private String type;
- private int age;
- private String playerAsString; //create one time -> use many times (carefull if it should change!)
- public Player(String name, String type, int age) {
- setName(name);
- setType(type);
- setAge(age);
- playerAsString = name + "(" + age + ")";
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getType() {
- return type;
- }
- public void setType(String type) {
- this.type = type;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- @Override
- public String toString() {
- return playerAsString;
- }
- @Override
- public int compareTo(Player other) {
- int comparisonResult = getName().compareTo(other.getName());//ascending (first current then other)
- if (comparisonResult == 0) {
- comparisonResult = Integer.compare(other.getAge(), getAge());//descending (first other then current)
- }
- return comparisonResult;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement