0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ABC - 029- A&B&C

Posted at

AtCoder ABC 029 A&B&C

AtCoder - 029

Typical DP Contest と Go langばかりやっててこっち全然手を付けてない
もう解けていないC問題とD問題にしぼるかなぁ

A問題

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

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

B問題

	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問題

  • 別解がメモリ無駄で遅い感じがしたので書き直したんだけど、、、変わらんかった。。。
    • s + "a" の順序がポイント。。。。ってほどでもないわ。
	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;
			}
		}

	}

C問題:別解

	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);

	}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?