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

AtCoder ABC 029 A&B&C AtCoder - 029

I'm just doing Typical DP Contest and Go lang and I haven't touched it at all I wonder if I will focus on the C and D problems that have not been solved anymore.

A 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

――The alternative solution was a waste of memory and I felt it was slow, so I rewrote it, but it didn't change. .. .. --The point is the order of s +" a ". .. .. .. Not so much.

	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: Another solution

	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 Programming Contest A & B & C & D
AtCoder Beginner Contest 169 A, B, C with ruby
atcoder ABC113 C problem
atcoder ABC115 C problem
AtCoder Beginner Contest 170 A, B, C up to ruby
Make a SOAP call in C #
Call a C function from Swift
NLP4J [006-034] 100 language processing knocks with NLP4J # 34 "A B"