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?

AtCoder ABC081A 解説と回答

Posted at

問題内容

標準入力に^[01]{3}$がきます。1は何文字かを出力すれば良い。

回答(C言語)

#include <stdio.h>

int main() {
  char a, b, c;
  scanf("%c%c%c", &a, &b, &c);
  printf("%d", a + b + c - 144);
  return 0;
}

コード解説

結構変な解き方をしてるのでご注意を

a, b, cが各文字を表します。
'0'はアスキーコードだと48で、'1'は49なので、
48を3かけた144をa, b, cの和から引きます。

すると、1の個数を計算することができます!


最後まで読んでいただきありがとうございます。

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?