ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ 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
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1485๋ฒ / ์ ์ฌ๊ฐํ [Go][Python3] (0) | 2021.02.10 |
---|---|
BOJ / 2217๋ฒ / ๋กํ [Go][Python3] (0) | 2021.02.09 |
BOJ / 11656๋ฒ / ์ ๋ฏธ์ฌ ๋ฐฐ์ด [Go][Python3] (0) | 2021.02.07 |
BOJ / 10799๋ฒ / ์ ๋ง๋๊ธฐ [Go][Python3] (0) | 2021.02.06 |
BOJ / 17219๋ฒ / ๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ [Go][Python3] (0) | 2021.02.05 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- python3
- java
- baekjoon
- ๋งฅ๋ถ
- ์ด๋ถํ์
- ์คํ
- ์๊ณ ๋ฆฌ์ฆ
- BOJ
- ballet
- Golang
- MongoDB
- ๋ฐฑ์ค
- dp
- dfs
- ํ๋ก์ด๋์์ฌ
- Algorithm
- ํด์๋งต
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- go
- ๋งฅ๋ถํ๋ก
- AWS
- ์๊ฐ๊ต์ฒด
- BFS
- ํ
- ๋ถํ ์ ๋ณต
- ๋ธ๋ฃจํธํฌ์ค
- ์๋ฐ
- ๋ฐ๋
- Macbook pro 2012 mid 13
- ๋ชฝ๊ณ ๋๋น
- Total
- Today
- Yesterday