2012年10月3日水曜日

開発環境

『初めてのプログラミング 第2版』(Chris Pine 著、長尾 高弘 訳、オライリー・ジャパン、2010年、ISBN978-4-87311-469-9)の 8章(配列とイテレータ), 8.3(練習問題)、配列の構築とソート を解いてみる。

その他参考書籍

配列の構築とソート

コード(TextWrangler)

sample.rb

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

puts "配列に書くのする単語を入力(空白で終了)"
words = []
while true
  word = gets.chomp
  break if word =~ /^\s*$/
  words.push word
end

sorted_words = words.sort
puts "ソート前", words
puts "ソート後", sorted_words

入出力結果(Terminal)

$ ./sample.rb
配列に書くのする単語を入力(空白で終了)
c#
python
perl
c
ruby
php

ソート前
c#
python
perl
c
ruby
php
ソート後
c
c#
perl
php
python
ruby
$

0 コメント:

コメントを投稿