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

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

 

4659๋ฒˆ: ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ฐœ์Œํ•˜๊ธฐ

์ข‹์€ ํŒจ์Šค์›Œ๋“œ๋ฅผ ๋งŒ๋“œ๋Š”๊ฒƒ์€ ์–ด๋ ค์šด ์ผ์ด๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ์‚ฌ์šฉ์ž๋“ค์€ buddy์ฒ˜๋Ÿผ ๋ฐœ์Œํ•˜๊ธฐ ์ข‹๊ณ  ๊ธฐ์–ตํ•˜๊ธฐ ์‰ฌ์šด ํŒจ์Šค์›Œ๋“œ๋ฅผ ์›ํ•˜๋‚˜, ์ด๋Ÿฐ ํŒจ์Šค์›Œ๋“œ๋“ค์€ ๋ณด์•ˆ์˜ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ์–ด๋–ค ์‚ฌ์ดํŠธ๋“ค์€ xvtp

www.acmicpc.net


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

๐ŸŽจ Go

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

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

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

	for {
		var password string
		fmt.Fscanln(reader, &password)
		if password == "end" {
			break
		}

		if checkPasswordAcceptable(password) {
			fmt.Fprintf(writer, "<%s> is acceptable.\n", password)
		} else {
			fmt.Fprintf(writer, "<%s> is not acceptable.\n", password)
		}
	}
}

func checkPasswordAcceptable(password string) bool {
	var prevLetter string
	var totalVowelCount, vowelCount, consonantCount int
	for i := 0; i < len(password); i++ {
		var curLetter = string(password[i])
		if isSame(prevLetter, curLetter) {
			return false
		}
		if isVowel(curLetter) {
			vowelCount++
			totalVowelCount++
			if vowelCount == 3 {
				return false
			}
			consonantCount = 0
		} else {
			consonantCount++
			if consonantCount == 3 {
				return false
			}
			vowelCount = 0
		}
		prevLetter = curLetter
	}
	if totalVowelCount == 0 {
		return false
	}
	return true
}

func isVowel(letter string) bool {
	var vowels = []string{"a", "e", "i", "o", "u"}
	for _, vowel := range vowels {
		if letter == vowel {
			return true
		}
	}
	return false
}

func isSame(prevLetter, letter string) bool {
	if prevLetter == letter && letter != "e" && letter != "o" {
		return true
	}
	return false
}

๐ŸŽจ Python3

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

def check_password_acceptable(password):
    prev_letter = ""
    total_vowel_count, vowel_count, consonant_count = 0, 0, 0
    for i in range(len(password)):
        cur_letter = password[i]
        if is_same(prev_letter, cur_letter):
            return False
        if is_vowel(cur_letter):
            vowel_count += 1
            total_vowel_count += 1
            if vowel_count == 3:
                return False
            consonant_count = 0
        else:
            consonant_count += 1
            if consonant_count == 3:
                return False
            vowel_count = 0
        prev_letter = cur_letter
    if total_vowel_count == 0:
        return False
    return True

def is_vowel(letter):
    vowels = ["a", "e", "i", "o", "u"]
    if letter in vowels:
        return True
    return False

def is_same(prev_letter, letter):
    if prev_letter == letter and letter != "e" and letter != "o":
        return True
    return False

if __name__ == "__main__":
    while True:
        password = sys.stdin.readline().rstrip()
        if password == "end":
            break

        if check_password_acceptable(password):
            print("<{}> is acceptable.".format(password))
        else:
            print("<{}> is not acceptable.".format(password))
728x90
๋Œ“๊ธ€