LoginSignup
4
3

More than 5 years have passed since last update.

paiza learningの足し算問題が解けない

Last updated at Posted at 2014-07-21

paiza learningの足し算問題。内容は、「半角スペースで区切られた2数を足して標準出力に出す」というもの。
pxemだと、「._._.+.nak.-.o.pxem」と書ける。

これがBash単体だとどうしても解けない。

1.sh
read line
a=($line)
expr ${a[0]} + ${a[1]}
2.sh
read line
a=($line)
echo $((a[0]+a[1]))
3.sh
read line
r=0
for i in $line;do
r=$((r+i))
done
echo $r

いずれも、「提出前動作確認」ではSuccessになるのだが、提出してみるとランタイムエラーになってしまう。

一応こうすれば100点になる。

4.sh
awk '{n+=$1+$2} END{print n}'

しかし、気持ち悪い。なんとかできないだろうか。

4
3
1

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
4
3