[JAVA] ABC --028 --A & B & C

AtCoder ABC 028 A&B&C AtCoder - 028

Subtly A-C is a series of simple times. .. ..

** 2019/05/03 postscript ** B problem code fix

A problem

	private void solveA() {
		int numN = nextInt();
		if (numN <= 59) {
			out.println("Bad");
		} else if (numN <= 89) {
			out.println("Good");
		} else if (numN <= 99) {
			out.println("Great");
		} else {
			out.println("Perfect");
		}
	}

B problem

** 2019/05/03 Code correction **

--I have to check Collectors

	private void solveB() {
		String wk = next();

		Map<String, Long> tmp = Arrays.stream(wk.split(""))
				.collect(Collectors.groupingBy(s -> s, Collectors.counting()));

		String[] ref = { "A", "B", "C", "D", "E", "F" };

		String res = Arrays.stream(ref).map(i -> tmp.getOrDefault(i, 0L)
				.toString()).collect(Collectors.joining(" "));

		/*
		 *This problem is trim because it will be WA if there is a blank at the end
		 */
		out.println(res.trim());

	}

Problem C: Brute force solution

--Try to add them all --Use set to avoid duplication --treeset because I want you to sort --Extract the third element from the end and output

	private void solveC2() {
		int[] wk = IntStream.range(0, 5).map(i -> nextInt()).toArray();

		Set<Integer> set = new TreeSet<Integer>();
		for (int i = 0; i < wk.length; i++) {
			for (int j = i + 1; j < wk.length; j++) {
				for (int k = j + 1; k < wk.length; k++) {
					set.add(wk[i] + wk[j] + wk[k]);
				}
			}
		}

		List<Integer> list = new ArrayList<Integer>(set);

		out.println(list.get(list.size() - 3));
	}

C problem: editorial solution

-Explanation from P.9 of editorial

-If $ a <b <c <d <e $ --The maximum value is - C+D+E ――The next big thing is - B+D+E ――The next largest is either of the following - A+D+E - B+C+E

	private void solveC() {
		int[] wk = IntStream.range(0, 5).map(i -> nextInt()).toArray();

		int res = Integer.max(wk[4] + wk[3]+ wk[0], wk[4] + wk[2]+ wk[1]);
		out.println(res);
	}

Recommended Posts

ABC --013-A & B & C
ABC --023 --A & B & C
ABC --036-A & B & C
ABC --010 --A & B & C
ABC --028 --A & B & C
ABC --015 --A & B & C
ABC --128 --A & B & C
ABC --012-A & B & C
ABC --018 --A & B & C
ABC --054 --A & B & C
ABC --017 --A & B & C
ABC --029- A & B & C
ABC --022 --A & B & C
ABC --019 --A & B & C
ABC --020 --A & B & C
ABC --030- A & B & C
ABC --127 --A & B & C
ABC --007 --A & B & C
ABC --132- A & B & C
ABC --026 --A & B & C
ABC --014- A & B & C
ABC --016 --A & B & C
ABC --011-A & B & C
ABC --031 --A & B & C
ABC --021 --A & B & C
ABC --025 --A & B & C
ABC --024 --A & B & C
ABC --027 --A & B & C
ABC --080- A & B & C
ABC --129- A & B & C & D
ABC --133- A & B & C & D
ABC --122 --A & B & C & D
ABC --125- A & B & C & D
ABC --130- A & B & C & D
ABC --126 --A & B & C & D
ABC --131- A & B & C & D & E
diverta 2019 Programming Contest A & B & C & D
AtCoder Beginner Contest 169 A, B, C with ruby
atcoder ABC113 C problem
ABC093 C --Same Integers
atcoder ABC115 C problem
AtCoder Beginner Contest 170 A, B, C up to ruby
A person writing C ++ tried writing Java
Make a SOAP call in C #
Call a C function from Swift
NLP4J [006-034] 100 language processing knocks with NLP4J # 34 "A B"