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 - 051- A&B&C

Posted at

AtCoder ABC 051 A&B&C

AtCoder - 051

A問題

  • カンマをスペースで置換する
	private void solveA() {
		Scanner scanner = null;
		String wk = "";

		try {
			scanner = new Scanner(System.in);
			wk = scanner.next();

			System.out.println(wk.replaceAll(",", " "));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

B問題

  • $X+Y+Z=S$をみたす数値を総当りで走査
	private void solveB() {
		Scanner scanner = null;
		int numK = 0;
		int s = 0;

		try {
			scanner = new Scanner(System.in);
			numK = scanner.nextInt();
			s = scanner.nextInt();

			int startK = 0;
			if (numK <= s / 3) {
				startK = numK;
			}
			int res = 0;
			for (int i = 0; i <= numK; i++) {
				for (int j = 0; j <= numK; j++) {
					if (s - i - j < 0) {
						break;
					} else if (s - i - j <= numK) {
						res++;
					}
				}
			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

C問題

  • 最速の方法は一つ
    • 下に表で記載した図が最速
      • 番号が道順
    • 解説の図がわかりやすい
1 2 3 4 5 6
1
2 4 4 4
3 4 2 E 3
4 4 S 1 3
5 3 3 3
6
	private void solveC() {
		Scanner scanner = null;
		int lineSX = 0;
		int lineSY = 0;
		int lineTX = 0;
		int lineTY = 0;

		try {
			scanner = new Scanner(System.in);
			lineSX = scanner.nextInt();
			lineSY = scanner.nextInt();
			lineTX = scanner.nextInt();
			lineTY = scanner.nextInt();

			StringBuilder builderRes = new StringBuilder();

			StringBuilder builderGo = new StringBuilder();
			StringBuilder builderBack = new StringBuilder();

			for (int i = 0; i < lineTY - lineSY; i++) {
				builderGo.append("U");
				builderBack.append("D");
			}
			for (int i = 0; i < (lineTX - lineSX); i++) {
				builderGo.append("R");
				builderBack.append("L");
			}

			builderRes.append(builderGo).append(builderBack);

			builderGo.setLength(0);
			builderBack.setLength(0);

			builderGo.append("L");
			builderBack.append("R");

			for (int i = 0; i < (lineTY - lineSY) + 1; i++) {
				builderGo.append("U");
				builderBack.append("D");
			}
			for (int i = 0; i < (lineTX - lineSX) + 1; i++) {
				builderGo.append("R");
				builderBack.append("L");
			}

			builderGo.append("D");
			builderBack.append("U");

			builderRes.append(builderGo).append(builderBack);

			System.out.println(builderRes.toString());

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
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?