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 1 year has passed since last update.

PythonでAtCoderのA問題完答

0
Last updated at Posted at 2025-05-12

はじめまして。AtCoderでの成績記録や、競技プログラミングで役立った実装・テクニックをまとめていく予定です。主にPythonで解いていますが、アルゴリズムや考え方の部分が参考になれば嬉しいです。自分の復習用も兼ねていますが、誰かの助けになれば幸いです!

現在の成績

早速ですがついにA問題を完答しました!

次は、B問題!と意気込んでいますが、先が長い...

というわけで、学んだことの整理やモチベを保つために投稿を始めることにしました!

今まで学んだこと

入力

二文字

x,y=map(int,input().split())

リスト

a=list(map(int,input().split()))

二次元リスト

a=[list(input()) for i in range(n)]

a = [[int(x) for x in input().split()] for i in range(n)]

a = [list(map(int,input().split())) for i in range(n)]

計算

x + y    x と y の和
x - y    x と y の差
x * y    x と y の積
x / y    x と y の商
x // y   x と y の商を切り下げたもの
x % y    x / y の剰余
-x       x の符号反転
+x       x そのまま
x ** y   x の y 乗

math

sqrt   平方根
floor 小数点以下を切り捨て
ceil  小数点以下を切り上げ

リストの各要素の出現個数をカウント

import collections

l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']

c = collections.Counter(l)
print(c)
# Counter({'a': 4, 'c': 2, 'b': 1})

print(c['a'])
# 4

print(c.keys())
# dict_keys(['a', 'b', 'c'])

print(c.values())
# dict_values([4, 1, 2])

print(c.items())
# dict_items([('a', 4), ('b', 1), ('c', 2)])

print(c.most_common())
# [('a', 4), ('c', 2), ('b', 1)]

print(c.most_common()[0])
# ('a', 4)

print(c.most_common()[0][0])
# a

print(c.most_common(2))
# [('a', 4), ('c', 2)]

文字とUnicode値を変換する関数

# 文字をUnicodeポイントに変換
print(ord('a'))
# 97

# Unicode値を文字列に変換
print(chr(97))
# a
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?