[JAVA] ABC - 029 - A & B & C.

AtCoder ABC 029 A&B&C AtCoder - 029

Ich mache nur Typical DP Contest und Go lang und habe es überhaupt nicht angefasst Ich frage mich, ob ich mich auf die C- und D-Probleme konzentrieren werde, die nicht mehr gelöst wurden.

Ein Problem

	private void solveA() {
		String s = next();

		out.println(s + "s");
	}

B Problem

	private void solveB() {
		int res = 0;
		for (int i = 0; i < 12; i++) {
			String s = next();
			int cnt = s.indexOf("r");
			if (cnt >= 0) {
				res++;
			}
		}
		out.println(res);
	}

C Problem

――Ich habe die alternative Lösung umgeschrieben, weil sie eine Verschwendung von Speicher war und sich langsam anfühlte, aber sie hat sich nicht geändert. .. ..

	private void solveC() {
		int numN = nextInt();
		saikiC(numN, "");
	}

	private void saikiC(int n, String s) {
		if (n == 0) {
			out.println(s);
			return;
		}

		for (int i = 0; i < 3; i++) {
			switch (i) {
			case 0:
				saikiC(n - 1, s + "a");
				break;
			case 1:
				saikiC(n - 1, s + "b");
				break;
			case 2:
				saikiC(n - 1, s + "c");
				break;
			default:
				break;
			}
		}

	}

Problem C: Eine andere Lösung

	private void solveC2() {
		int numN = nextInt();

		Set<String> wk = new TreeSet<String>();
		printC2(numN, 1, 1, "", wk);
		printC2(numN, 1, 2, "", wk);
		printC2(numN, 1, 3, "", wk);
		for (String string : wk) {
			out.println(string);
		}
	}

	private void printC2(int n, int current, int index, String s, Set<String> wk) {
		if (current > n) {
			wk.add(s);
			return;
		}
		String tmp = s;
		switch (index) {
		case 1:
			tmp = tmp + "a";
			break;
		case 2:
			tmp = tmp + "b";
			break;
		case 3:
			tmp = tmp + "c";
			break;

		default:
			break;
		}
		printC2(n, current + 1, 1, tmp, wk);
		printC2(n, current + 1, 2, tmp, wk);
		printC2(n, current + 1, 3, tmp, wk);

	}

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 - 134 - A & B & C & D & E.
ABC - 131 - A & B & C & D & E.
diverta 2019 Programmierwettbewerb A & B & C & D.
AtCoder Anfängerwettbewerb 169 A, B, C mit Rubin
atcoder ABC113 C Problem
atcoder ABC115 C Problem
AtCoder Anfängerwettbewerb 170 A, B, C bis Rubin
Machen Sie einen SOAP-Aufruf in C #
Rufen Sie C-Sprachfunktionen von Swift aus auf
NLP4J 100 Sprachverarbeitungsklopfen mit NLP4J # 34 "A B"