ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

2947๋ฒˆ: ๋‚˜๋ฌด ์กฐ๊ฐ

์ฒซ์งธ ์ค„์— ์กฐ๊ฐ์— ์“ฐ์—ฌ ์žˆ๋Š” ์ˆ˜๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 5๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉฐ, ์ค‘๋ณต๋˜์ง€ ์•Š๋Š”๋‹ค. ์ฒ˜์Œ ์ˆœ์„œ๋Š” 1, 2, 3, 4, 5๊ฐ€ ์•„๋‹ˆ๋‹ค.

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

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

import (
	"bufio"
	"fmt"
	"os"
)

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

	var arr = make([]int, 5)
	fmt.Fscanln(reader, &arr[0], &arr[1], &arr[2], &arr[3], &arr[4])

	for arr[0] != 1 || arr[1] != 2 || arr[2] != 3 || arr[3] != 4 || arr[4] != 5 {
		for i := 0; i < 4; i++ {
			if arr[i] > arr[i+1] {
				arr[i], arr[i+1] = arr[i+1], arr[i]
				for j := 0; j < 4; j++ {
					fmt.Fprintf(writer, "%d ", arr[j])
				}
				fmt.Fprintf(writer, "%d\n", arr[4])
			}
		}
	}
}

๐ŸŽจ Python3

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

if __name__ == "__main__":
    arr = list(map(int, sys.stdin.readline().split()))

    while arr[0] != 1 or arr[1] != 2 or arr[2] != 3 or arr[3] != 4 or arr[4] != 5:
        for i in range(4):
            if arr[i] > arr[i+1]:
                arr[i], arr[i+1] = arr[i+1], arr[i]
                print('{} {} {} {} {}'.format(arr[0], arr[1], arr[2], arr[3], arr[4]))
728x90
๋Œ“๊ธ€