์ƒˆ์†Œ์‹

๐Ÿงฎ PS

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] (Python) - ์‹ ๊ทœ ์•„์ด๋”” ์ถ”์ฒœ

  • -

* ๋ฌธ์ œ ๋งํฌ

programmers.co.kr/learn/courses/30/lessons/72410

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์‹ ๊ทœ ์•„์ด๋”” ์ถ”์ฒœ

์นด์นด์˜ค์— ์ž…์‚ฌํ•œ ์‹ ์ž… ๊ฐœ๋ฐœ์ž ๋„ค์˜ค๋Š” "์นด์นด์˜ค๊ณ„์ •๊ฐœ๋ฐœํŒ€"์— ๋ฐฐ์น˜๋˜์–ด, ์นด์นด์˜ค ์„œ๋น„์Šค์— ๊ฐ€์ž…ํ•˜๋Š” ์œ ์ €๋“ค์˜ ์•„์ด๋””๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์—…๋ฌด๋ฅผ ๋‹ด๋‹นํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. "๋„ค์˜ค"์—๊ฒŒ ์ฃผ์–ด์ง„ ์ฒซ ์—…๋ฌด๋Š” ์ƒˆ๋กœ

programmers.co.kr

* ๋ฌธ์ œ ๋ถ„๋ฅ˜ , ๋‚œ์ด๋„

 

 ๋ถ„๋ฅ˜ : 2021 KAKAO BLIND RECRUITMENT

 ๋‚œ์ด๋„ : Lv1

 

* ํŒŒ์ด์ฌ(Pyhton) ์ฝ”๋“œ

 

def solution(new_id) :
	#step1 ๋Œ€๋ฌธ์ž -> ์†Œ๋ฌธ์ž๋กœ ์น˜ํ™˜
	new_id = new_id.lower()
	#step2 ์†Œ๋ฌธ์ž, ์ˆซ์ž, -, _, . ๋ฅผ ์ œ์™ธํ•œ ๋ฌธ์ž์—ด ์ œ๊ฑฐ
	for idx, char in enumerate(new_id) :
		if not(char.isdigit() or char.islower() or char == "-" or char == "_" or char == ".") :
			new_id = new_id.replace(char, "")
	#step 4
	new_id = new_id.strip(".")
	#step 3
	while (".." in new_id) :
		new_id = new_id.replace("..", ".")
	#step5
	if (len(new_id) == 0):
		new_id = "aaa"
	#step6
	elif (len(new_id) >= 16) :
		new_id = new_id[0:15]
		new_id = new_id.strip(".")
	#step7
	elif (len(new_id) <= 2) :
		while(len(new_id) != 3) :
			new_id += new_id[-1]
	return new_id

 

* ํ’€์ด ๋ฐฉ๋ฒ•

 

  • ํŠน๋ณ„ํ•œ ํ’€์ด๋ฐฉ๋ฒ•์€ ํ•„์š”ํ•˜์ง€ ์•Š์•˜๊ณ , ๋ฌธ์ œ ๊ทธ๋Œ€๋กœ์˜ ๋‚ด์šฉ์„ ๊ตฌํ˜„ํ•˜๋ฉด ๋˜์—ˆ๋‹ค.
  • strip() , isdigit() replace(old,new) ๋“ฑ์˜ ๊ฐ„๋‹จํ•œ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ ํ•จ์ˆ˜๊ฐ€ ํ•„์š”ํ–ˆ๋‹ค.

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.