LoginSignup
0
0

【Atcoder初心者向け】入力コードの書き方

Last updated at Posted at 2024-04-28

私自身、友人の紹介でAtcoderを始めたとき、まず入力の仕方がわからず困っていました。同じことで悩んでいる方も多いと思い、本記事では入力別に、pythonの入力コードを紹介します。

Atcoderとは

Atcoderとは国内の競技プログラミングサイトです。誰でも無料で簡単に参加でき、問題の正答数や解答時間に応じて、レートが設けられています。

パターン別入力方法

入力は大きく分けて複数入力配列入力行列型入力の3パターンがあります。

複数入力

w,b=map(int,input().split())

複数入力にはmap関数を用い、split()は要素間に空白をあけて入力することを意味します。
数字の場合はint、文字の場合はstrを用います。

配列入力

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

listは配列として入力するときに用いる関数です。

行列型入力

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

各要素間にスペースが空いている場合は,input().split()になります.

まとめ

Atcodetでは上記の3つの入力パターンを使えば、ほとんどすべての問題の入力に対応できます。ぜひ活用してください!

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