ν΄λΉλ¬Έμ λ§ν¬ : https://programmers.co.kr/learn/courses/30/lessons/81301
λͺ©μ°¨
- 1. λ¬Έμ μ€λͺ
- 2. μ νμ¬ν
- 3. νμ΄μ¬ νμ΄
- 4. νμ΄μ¬ νμ΄ μ€λͺ
- 5. μνμ°©μ€
- 6. λλμ
1. λ¬Έμ μ€λͺ
λ€μ€μ νλ‘λκ° μ«μλμ΄ κ²μμ νκ³ μμ΅λλ€. μ«μμ μΌλΆ μ«μμ΄μ§λ§ λ¬Έμμ΄μ΄ κ°μ΄ μ‘΄μ¬νλ λ¬Έμμ΄μ 건λ€μ£Όλ λͺ¨λ μ«μλ‘ λ³νμμΌμΌ νλ κ²μμ λλ€. μλ₯Ό λ€μ΄, '23four5six7" μ΄λΌλ κ°μ΄ μ£Όμ΄μ§λ©΄, 234567 μ΄λΌλ λͺ¨λ μ«μλ‘ λ κ°μ λ°νν΄μ€μΌν©λλ€.
2. μ νμ¬ν
- 1 ≤ sμ κΈΈμ΄ ≤ 50
- sκ° "zero" λλ "0"μΌλ‘ μμνλ κ²½μ°λ μ£Όμ΄μ§μ§ μμ΅λλ€.
- return κ°μ΄ 1 μ΄μ 2,000,000,000 μ΄νμ μ μκ° λλ μ¬λ°λ₯Έ μ λ ₯λ§ sλ‘ μ£Όμ΄μ§λλ€.
- μ νμ± ν μ€νΈ 10μ΄
- μ)
s | result |
"one4seveneight" | 1478 |
"23four5six7" | 234567 |
"2three45sixseven" | 234567 |
"123" | 123 |
3. νμ΄μ¬ νμ΄
2κ°μ§λ‘ νμμ΅λλ€. 첫λ²μ§Έ νμ΄λ μκ° μ νμΌλ‘ κ°μ λ νμ΄λ°©λ² 2λ‘ μ μΆνμμ΅λλ€.
νμ΄1
def solution(s):
answer = 0
if "one" in s:
s = s.replace("one","1")
if "two" in s:
s = s.replace("two","2")
if "three" in s:
s = s.replace("three","3")
if "four" in s:
s = s.replace("four","4")
if "five" in s:
s = s.replace("five","5")
if "six" in s:
s = s.replace("six","6")
if "seven" in s:
s = s.replace("seven","7")
if "eight" in s:
s = s.replace("eight","8")
if "nine" in s:
s = s.replace("nine","9")
answer = int(s)
return answer
νμ΄ 1 νμ΄μ¬ νμ΄ κ²°κ³Ό
ν
μ€νΈ 1 γ ν΅κ³Ό (0.01ms, 10.4MB)
ν
μ€νΈ 2 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 3 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 4 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 5 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 6 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 7 γ μ€ν¨ (λ°νμ μλ¬)
ν
μ€νΈ 8 γ μ€ν¨ (λ°νμ μλ¬)
ν
μ€νΈ 9 γ μ€ν¨ (λ°νμ μλ¬)
ν
μ€νΈ 10 γ ν΅κ³Ό (0.02ms, 10.5MB)
νμ΄ 1 μ±μ κ²°κ³Ό
μ νμ±: 70.0
ν©κ³: 70.0 / 100.0
νμ΄ 2
def solution(s):
answer = s
dictionary = {
"zero" : "0",
"one" : "1",
"two" : "2",
"three" : "3",
"four" : "4",
"five" : "5",
"six" : "6",
"seven" : "7",
"eight" : "8",
"nine" : "9"
}
for item in dictionary.items():
answer = answer.replace(item[0], item[1])
return int(answer)
νμ΄ 2 νμ΄μ¬ νμ΄ κ²°κ³Ό
ν
μ€νΈ 1 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 2 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 3 γ ν΅κ³Ό (0.03ms, 10.4MB)
ν
μ€νΈ 4 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 5 γ ν΅κ³Ό (0.02ms, 10.3MB)
ν
μ€νΈ 6 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 7 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 8 γ ν΅κ³Ό (0.03ms, 10.4MB)
ν
μ€νΈ 9 γ ν΅κ³Ό (0.02ms, 10.4MB)
ν
μ€νΈ 10 γ ν΅κ³Ό (0.02ms, 10.4MB)
νμ΄ 2 μ±μ κ²°κ³Ό
μ νμ±: 100.0
ν©κ³: 100.0 / 100.0
4. νμ΄μ¬ νμ΄ μ€λͺ
μΌμΌν μ½λλ₯Ό μννλ κ²λ³΄λ€ νλ²μ μννλ κ²μ λͺ©νλ‘νκ³ , λ°λ³΅λ¬Έμ μ νμ©ν΄μ μκ°μ λ¨μΆνλ κ²μ΄ μ€μνλ€λ κ²μ κΉ¨λ¬μμ΅λλ€.
replace λ©μλμ key, value κ°μ λν΄μ items() λ₯Όνλ©΄ 첫λ²μ§Έλ key, λλ²μ§Έλ ν΄λΉ keyμ λν value κ°μ΄ λμ΅λλ€.
5. μνμ°©μ€
return re.sub('\.\.+','.',x)
0μ κ³ λ €νμ§ μκ³ , κ³μ μ½λλ₯Ό μμ νλλ°, λ°νμ μλ¬κ° λλ μ΄μ κ° zero μ λν λμ λ리λ₯Ό λ§λ€μ΄μ£Όμ§ μμμμ κΉ¨λ«κ³ , λ€μ μ€ννμλλ μ±κ³΅νμμ΅λλ€.
6. λλμ
λμ λ리 ννμ, replace ꡬ문μ λν νμ΅μ νμμ΅λλ€.