LoginSignup
2
2

More than 3 years have passed since last update.

はじめてのプロコンメモ(その1)

Posted at

Python3で挑むにあたり忘れないようにメモ書きを残しておく
AtCoder に登録したら次にやること ~ これだけ解けば十分闘える!過去問精選 10 問 ~
を類題も含めてといた記録のメモ

標準入力

# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())
# スペース区切りの整数の入力
b, c = map(int, input().split())
# 文字列の入力
s = input()
# 出力
print("{} {}".format(a+b+c, s))

練習1

A - Product

シカのAtCoDeerくんは二つの正整数 
a,bを見つけました。 
aとbの積が偶数か奇数か判定してください。

解答


a,b = map(int, input().split())
if a*b % 2 == 0:
    print('Even')
else:
    print('Odd')

練習2

ABC 064 A - RGB Cards

AtCoDeer君は、赤、緑、青色のカードを持っています。
それぞれのカードには 1以上9以下の整数が書かれており、赤色のカードには 
r、緑色のカードにはg、青色のカードには bが書かれています。
3つのカードを左から順に赤、緑、青色の順に並べ、左から整数を読んだときにこれが 4の倍数であるか判定しなさい。

解答

r,g,b = map(int, input().split())
sum = r*100 + g*10 + b
if sum % 4 == 0:
    print('YES')
else:
    print('NO')

練習3

ABC 088 A - Infinite Coins

E869120 は 1円硬貨をA枚と500円硬貨を無限枚持っています.
これらの硬貨だけを使うことによって, ちょうど N円を支払うことができるかを判定しなさい.

解答

Nyen = int(input())
Amai = int(input())

if Nyen % 500 <= Amai:
    print('Yes')
else:
    print('No')

練習4

ABC 082 A - Round Up the Mean

2つの正整数 a, bが与えられます。 a, bの平均値をxとします。 xの小数点以下を切り上げて得られる整数を出力してください。

つくった解答

import math
a,b = map(int, input().split())
print(math.ceil((a+b)/2))

模範解答

a, b = map(int, input().split())
print((a + b + 1) // 2)

参考文献

演算子の切り上げ
https://python.ms/sub/misc/division/#%EF%BC%93%E3%81%A4%E3%81%AE%E3%82%84%E3%82%8A%E6%96%B9

練習

参考文献

AtCoder に登録したら次にやること ~ これだけ解けば十分闘える!過去問精選 10 問 ~

2
2
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
2
2