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

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

 

11478๋ฒˆ: ์„œ๋กœ ๋‹ค๋ฅธ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์˜ ๊ฐœ์ˆ˜

์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. S๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ธธ์ด๋Š” 1,000 ์ดํ•˜์ด๋‹ค.

www.acmicpc.net


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

๐ŸŽจ Go

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

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

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

	var s string
	fmt.Fscanln(reader, &s)
	strs := map[string]bool{}
	for i := 0; i < len(s); i++ {
		for j := 1; i+j <= len(s); j++ {
			strs[s[i:i+j]] = true
		}
	}
	fmt.Fprintln(writer, len(strs))
}

๐ŸŽจ Python3

# https://www.acmicpc.net/submit/11478
import sys

if __name__ == "__main__":
    s = sys.stdin.readline().rstrip()
    strs = {}
    for i in range(len(s)):
        for j in range(1, len(s)-i+1):
            strs[s[i:i+j]] = True
    print(len(strs))
728x90
๋Œ“๊ธ€