Created
March 24, 2012 16:25
-
-
Save aoi0308/2184835 to your computer and use it in GitHub Desktop.
コップ本第2版のP.76のプログラムを少しいじったもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source | |
def widthOfLength(s: String): Int = s.length.toString.length | |
if (args.length == 0) { | |
Console.err.println("Please enter filename") | |
sys.exit(-1) | |
} | |
val lines = Source.fromFile(args(0)).getLines().toList | |
val maxWidth = lines.map(widthOfLength).max | |
val output = lines.map {line => | |
val padding = " " * (maxWidth - widthOfLength(line)) | |
padding + line.length + " | " + line | |
} | |
println(output.mkString("\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment