LoginSignup
0
0

More than 1 year has passed since last update.

【base shellscript】競技プログラミングでの値取得 01

Posted at

入力値

・パターン1(文字列)

入力

入力例1
abcdefg

#!/bin/bash

# 取得方法(read 変数)で取得できる。
read s
# 出力
echo $s
出力結果

abcdefg

・パターン2(数値)※パターン1と同じ

・パターン3(数値)※文字列も恐らく同じ

入力

入力例1
A B

#!/bin/bash

# 取得方法(read 変数)で取得できる。
read y z
# 出力
echo $y
echo $z
出力結果

AB

・パターン4(数値 N + N行)N行を配列で受け取る

入力

入力例1
4
200
500
555
124

#!/bin/bash

# 頭の 4 を取得
read N
# 配列で受け取り
A=(`tr ' ' '\n'`)

# 配列要素 全出力
# echo ${A[@]}
出力結果

200
500
555
124

あとがき

・追記していければと思います。何かの役に立てれば幸いです。ごっつあんです!

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