티스토리 뷰

👩🏻‍💻 문제

 

7596번: MP3 Songs

Output will consist of the scenario number, the first being 1, on a line on its own. This will be followed by n lines showing the tune names from the input list, sorted in alphabetical order, one name per line. Case should be ignored. 

www.acmicpc.net


✍🏻 풀이

🎨 Go

// https://www.acmicpc.net/problem/7596
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var count int = 1
	for {
		var n int
		fmt.Fscanln(reader, &n)
		if n == 0 {
			break
		}
		var playlist []string
		for i := 0; i < n; i++ {
			var input string
			input, _ = reader.ReadString('\n') // 공백 포함하여 입력 받기 위해 ReadString() 사용
			playlist = append(playlist, strings.TrimRight(input, "\n"))
		}
		sort.Strings(playlist)
		fmt.Fprintln(writer, count)
		for _, v := range playlist {
			fmt.Fprintln(writer, v)
		}
		count++
	}
}

🎨 Python3

# https://www.acmicpc.net/problem/7596
import sys

if __name__ == "__main__":
    count = 1
    while True:
        n = int(sys.stdin.readline())
        if n == 0:
            break
        playlist = []
        for i in range(n):
            playlist.append(sys.stdin.readline().rstrip())
        playlist.sort()
        print(count)
        for song in playlist:
            print(song)
        count += 1
728x90
댓글