ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ 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
- BOJ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- Algorithm
- ๋ฐ๋
- ์คํ
- ์๋ฐ
- dp
- Golang
- ์๊ฐ๊ต์ฒด
- ๋งฅ๋ถ
- java
- ์๊ณ ๋ฆฌ์ฆ
- BFS
- ๋งฅ๋ถํ๋ก
- dfs
- baekjoon
- ์ด๋ถํ์
- MongoDB
- ํด์๋งต
- ballet
- ํ
- python3
- ๋ธ๋ฃจํธํฌ์ค
- ํ๋ก์ด๋์์ฌ
- Macbook pro 2012 mid 13
- ๋ฐฑ์ค
- go
- ๋ถํ ์ ๋ณต
- ๋ชฝ๊ณ ๋๋น
- AWS
- Total
- Today
- Yesterday