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

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

 

11140๋ฒˆ: LOL

๋‹น์‹  ์นœ๊ตฌ ์ง€๋ฏผ์ด๋Š” ์ง€๊ธˆ ํ•  ์ผ์ด ์—†๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋งค์šฐ ์‹ฌ์‹ฌํ•˜๋‹ค. ๊ทธ๋ž˜์„œ ์“ธ๋ฐ์—†๋Š” ์ง“์œผ๋กœ ์‹œ๊ฐ„์„ ๋•Œ์šฐ๋ ค๊ณ  ํ•œ๋‹ค. ๊ทธ๋ž˜์„œ ๋‹จ์–ด ํ•˜๋‚˜๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๋‹จ์–ด์— 'lol'์ด ๋“ค์–ด๊ฐ€๋„๋ก ๊ธ€์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝ

www.acmicpc.net


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

๐ŸŽจ Go

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

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

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

	var t int
	fmt.Fscanln(reader, &t)
	for i := 0; i < t; i++ {
		var input string
		fmt.Fscanln(reader, &input)
		fmt.Fprintln(writer, solve(input))
	}
}

func solve(input string) int {
	match, _ := regexp.MatchString("l([a-z])l", input)
	if strings.Contains(input, "lol") {
		return 0
	} else if strings.Contains(input, "lo") || strings.Contains(input, "ol") || strings.Contains(input, "ll") || match {
		return 1
	} else if strings.Contains(input, "l") || strings.Contains(input, "o") {
		return 2
	}
	return 3
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/11140
import sys
import string

def solve(input):
    if "lol" in input:
        return 0
    elif "lo" in input or "ol" in input or "ll" in input or any("l" + x + "l" in input for x in string.ascii_lowercase):
        return 1
    elif "l" in input or "o" in input:
        return 2
    return 3

if __name__ == "__main__":
    t = int(sys.stdin.readline())
    for i in range(t):
        input = sys.stdin.readline().rstrip()
        print(solve(input))
728x90
๋Œ“๊ธ€