아무것도 입력하지 않으면 반복문을 빠져나온다.
Bash
bash
while :; do
read a b
if [ "$a$b" == "" ]; then
break
fi
echo $((a + b))
done
1
2
3
4
5
6
7
2
3
4
5
6
7
Node.js
javascript
let list = require("fs").readFileSync(0).toString().trim().split("\n");
for (let l of list) {
let [a, b] = l.split(" ").map(Number);
console.log(a+b);
}
1
2
3
4
5
2
3
4
5
PHP
php
<?php
while (1) {
unset($a, $b);
fscanf(STDIN, "%d %d", $a, $b);
if ($a == "" || $b == "") { break; }
echo $a + $b."\n";
}
?>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Python3
python
try:
while 1:
a, b = map(int, input().split())
print(a+b)
except:
pass
1
2
3
4
5
6
2
3
4
5
6
Ruby
ruby
begin
while 1
a, b = gets.chomp.split().map {|i| i.to_i}
puts a+b
end
rescue
nil
end
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
begin
== 다른 언어의 try
rescue
는 cache
, except
와 같은 기능을 하며, else
, ensure
등의 기능이 더 있다. nil
은 null
와 비슷한 역할을 하지만, Python
의 pass
처럼 사용할 수도 있다.
Comments
Not supported comment edit and upvote
You can do it on this page if you want.