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

Posted at

AtCoder ABC 090 A&B&C

AtCoder - 090

A問題

  • {$i=j$}の位置の文字を出力
	private void solveA() {
		Scanner scanner = null;

		String[] wkArray = new String[3];

		try {
			StringBuffer buff = new StringBuffer();
			scanner = new Scanner(System.in);
			for (int i = 0; i < 3; i++) {
				wkArray[i] = scanner.next();
			}

			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					if (i == j) {
						buff.append((wkArray[i].toCharArray())[j]);
					}
				}
			}

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

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

B問題

  • 5桁の数なので、$[1][2][3][4][5]$とあらわしたとき
    • $[1]=[5],[2]=[4]$が成り立つ
    • $[3]$はどのような数字でも良い
	private void solveB() {
		Scanner scanner = null;

		int startNum = 0;
		int endNum = 0;

		try {
			scanner = new Scanner(System.in);
			startNum = scanner.nextInt();
			endNum = scanner.nextInt();

			int count = 0;
			for (int i = startNum; i <= endNum; i++) {
				char[] num = Integer.toString(i).toCharArray();
				if (num[0] == num[4] && num[1] == num[3]) {
					count++;
				}
			}

			System.out.println(count);

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

C問題

  • 以下が常に成り立つ
    • 偶数回返されるカードは最後の操作で表
    • 奇数回返されるカードは最後の操作で裏
  1. {$N=1,M=1$}の場合は$1$(必ず裏になる)
  2. {$N=1,M\neq1$}の場合は、両端の二つは表になる(両端は偶数回の操作/中は奇数回の操作が実行される)
  3. {$N\neq1,M=1$}の場合は、両端の二つは表になる(両端は偶数回の操作/中は奇数回の操作が実行される)
  4. {$N\neq1,M\neq1$}の場合は、2,4を組み合わせると周囲1マスは表になり、中は裏になる
	private void solveC2() {
		Scanner scanner = null;
		long numN = 0;
		long numM = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextLong();
			numM = scanner.nextLong();

			if (numN == 1 && numM == 1) {
				System.out.println(1);
			} else if (numN == 1 && numM > 1) {
				int wkEdge = 2;
				long wkNaka = numM - wkEdge;
				System.out.println(wkNaka);
			} else if (numN > 1 && numM == 1) {
				int wkEdge = 2;
				long wkNaka = numN - wkEdge;
				System.out.println(wkNaka);
			} else {
				long wkNaka = (numN - 2) * (numM - 2);
				System.out.println(wkNaka);
			}

		} 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?