LoginSignup
0
0

More than 1 year has passed since last update.

AtCoderのabc135の[A - Harmony]

Posted at

読んで欲しい人

・似たような問題を解く未来の私
・プログラミングが詳しい方(教えてください) 

注意

AtCoderのabc135のA - Harmonyのネタバレあり。

ACしたコード

#include <stdio.h>
int	main(void)
{
	int	a,b;
	scanf("%d%d",&a,&b);
	// printf("%d %d\n",a,b);

	if(a % 2 == 0 && b % 2 == 0 || a % 2 != 0 && b % 2 != 0){
		printf("%d\n", (a + b) / 2);
	} else {
		printf("IMPOSSIBLE\n");
	}
	return (0);
}

調べた事まとめ

問題文の理解
相違なる整数 → 異なる整数

奇数・偶数の知識
奇数 + 奇数 = 偶数

絶対値の知識
絶対値を表す記号

| -2 | → 2
| 2 |  → 2

解き方を思い出す為には

入力例の数字がどのような関係なのか考える。
・A と B が 偶数 or 奇数同士なのか、偶数と奇数なのか。

いろんなACしたコード

(探し中)

0
0
5

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