cat in.txt | ruby stdin_stdout.rb > out.txtruby stdin_stdout.rb < in.txt > out.txt| 3 | |
| 1 2 3 | |
| 11 | |
| 10 | |
| 5 | |
| 0 9 8 7 6 |
| [["1", "2", "3"]] | |
| [["1", "2", "3"], "error"] | |
| [["1", "2", "3"], "error", ["0", "9", "8", "7", "6"]] |
| # $stdin/$stdout son de la clase File | |
| # STDIN/STDOUT | |
| array = [] | |
| =begin | |
| until (linea = $stdin.gets).nil? | |
| next if linea.is_a? Numeric | |
| linea = linea.to_i | |
| str = $stdin.gets.split(' ') | |
| if str.size == linea | |
| array.push(str) | |
| else | |
| array.push('error') | |
| end | |
| $stdout.puts array.to_s | |
| end | |
| =end | |
| until (linea = STDIN.gets).nil? | |
| next if linea.is_a? Numeric | |
| linea = linea.to_i | |
| str = STDIN.gets.split(' ') | |
| if str.size == linea | |
| array.push(str) | |
| else | |
| array.push('error') | |
| end | |
| STDOUT.puts array.to_s | |
| end | |
| # input | |
| =begin | |
| 3 | |
| 1 2 3 | |
| 11 | |
| 10 | |
| 5 | |
| 0 9 8 7 6 | |
| =end | |
| # output | |
| =begin | |
| [["1", "2", "3"]] | |
| [["1", "2", "3"], "error"] | |
| [["1", "2", "3"], "error", ["0", "9", "8", "7", "6"]] | |
| =end |