1
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.

Qiita Engineer Festa 2024(キータ・エンジニア・フェスタ 2024) - Qiita
において、約1ヶ月で38記事という大量の記事の投稿を要求されることがわかった。
そこで、あまりコストをかけずに記事数を稼ぐ方法を考えた結果、「Welcome to AtCoder を様々な言語で解く」ことを思いついた。
単に解くだけでなく、使用する言語仕様の解説を入れれば、記事として一応成立するだろう。

Welcome to AtCoder

PracticeA - Welcome to AtCoder

Welcome to AtCoder では、以下の形式で整数 $a$, $b$, $c$ および文字列 $s$ が入力として与えられる。

a
b c
s

この入力をもとに、与えられた整数の和 $sum = a + b + c$ および文字列 $s$ を、以下の形式で出力することが求められる。

sum s

今回使用する Bash のコマンド

入力

read コマンド – 標準入力から変数に代入する | Linuxコマンド.NET

read コマンドを用いると、標準入力から1行読んで指定した変数に代入できる。

read a

複数の変数を指定すると、入力の行をフィールドに分割し、それぞれの変数に代入できる。

read b c

変数を指定しない場合、変数 REPLY に代入する。

read

演算

Linux: bashシェルにおいて数値計算を行ういくつかの方法 #Bash - Qiita

let コマンドを用いると、式の計算を行い、結果を変数に代入できる。

let sum=a+b+c

出力

echoコマンドの詳細まとめました【Linuxコマンド集】

echo コマンドを用いると、文字列を出力できる。
" で囲んだ文字列の中に $ に続いて変数名を書くと、その変数の内容をその位置に展開できる。

echo "$sum $REPLY"

提出コード

read a
read b c
read
let sum=a+b+c
echo "$sum $REPLY"

提出 #54440799 - AtCoder Beginners Selection

1
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
1
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?