結果

問題 No.297 カードの数式
ユーザー mitsuomitsuo
提出日時 2016-05-15 10:37:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,785 bytes
コンパイル時間 2,692 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 57,272 KB
最終ジャッジ日時 2024-04-15 21:45:27
合計ジャッジ時間 8,196 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package jp.fedom.challange.yuki.l2.q297;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] c = new String[N];
		for (int i = 0; i < N; i++) {
			c[i] = sc.next();
		}
		sc.close();
		System.out.println(solve(N, c));
	}

	public static String solve(int N, String[] c) {
		PriorityQueue<Integer> n = new PriorityQueue<>(new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return o2 - o1;
			};
		});
		PriorityQueue<Character> ex = new PriorityQueue<>(new Comparator<Character>() {
			@Override
			public int compare(Character o1, Character o2) {
				return o1 - o2;
			};
		});
		PriorityQueue<Character> nex = new PriorityQueue<>(new Comparator<Character>() {
			@Override
			public int compare(Character o1, Character o2) {
				return o2 - o1;
			};
		});
		for (String s : c) {
			if (s.equals("+") || s.equals("-")) {
				ex.add(s.charAt(0));
			} else {
				n.add(new Integer(s));
			}
		}
		System.out.println(n);
		System.out.println(ex);

		int max = 0;
		int min = 0;

		while (n.size() > ex.size()) {
			max *= 10;
			max += n.poll();
		}
		PriorityQueue<Integer> nc = new PriorityQueue<>(n);
		System.out.println(nc);
		System.out.println(n);
		nex.addAll(ex);
		int absmax = max;

		while (ex.size() > 0) {
			char ch = (char) ex.poll();
			if (ch == '-') {
				max -= n.poll();
			} else {
				max += n.poll();
			}
		}

		nc.add(absmax);
		nex.add('+');
		System.out.println(nc);
		while (nex.size() > 0) {
			char ch = (char) nex.poll();
			if (ch == '-') {
				min -= nc.poll();
			} else {
				min += nc.poll();
			}
		}

		return max + " " + min;
	}
}
0