/* * Compilation: kotlinc Students.kt * Execution: kotlin StudentsKt < students.txt * * Reads in the integer n from standard input, then a list * of n student records, where each record consists of four * fields, separated by whitespace: * - first name * - last name * - email address * - which section they're in * * Then, print out a list of email address of students in section 4 and 5. * * % kotlin StudentsKt < students.txt * Sarah Wang twang 7 * Austin Taylor actaylor 1 * David Rosner drosner 4 * Rebecca Allen rebeccaa 7 * Rajiv Ayyangar ayyangar 7 * Daniel Barrett drbarret 8 * Nic Byrd nbyrd 7 * Emily Capra ecapra 8 * Johnny Clore jclore 7 * ... * * % Section 4 * --------- * drosner * jcharles * jph * mlampert * ... * * Section 5 * --------- * giwank * agrozdan * ajh * akornell * ... * */ fun main(args: Array) { val scanner = java.util.Scanner(System.`in`) // read the number of students val n = scanner.nextInt() // initialize four parallel arrays val first = Array(n) { "" } val last = Array(n) { "" } val email = Array(n) { "" } val section = IntArray(n) // read in the data for (i in 0 until n) { first[i] = scanner.next() last[i] = scanner.next() email[i] = scanner.next() section[i] = scanner.nextInt() } // print email addresses of all students in section 4 println("""Section 4 |--------- """.trimMargin()) for (i in 0 until n) { if (section[i] == 4) println(email[i]) } println() // print email addresses of all students in section 5 println("""Section 5 |--------- """.trimMargin()) for (i in 0 until n) { if (section[i] == 5) { println(email[i]) } } }