๐ŸŒฑ → ๐ŸŒณ

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ - python ๋ณธ๋ฌธ

Algorithms

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ - python

thals0 2023. 7. 25. 13:01
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/12951

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

๋ช‡๋ช‡ ํ…Œ์ŠคํŠธ์—์„œ ๋Ÿฐํƒ€์ž„์—๋Ÿฌ ๋ฐœ์ƒ

์ด์œ ๊ฐ€ ๋ญ˜๊นŒ ?

def solution(s):
    answer = ''
    ans = []
    arr = (s.split(' '))
    for s in arr:
        for i in s:
            ans.append(i.lower())
        ans[0] = ans[0].upper()
        answer += ''.join(ans)
        answer += ' '
        ans = []
    return answer[:-1]

 

์ด๊ฑด ๋˜ ์™œ ๋ช‡๋ช‡ ํ…Œ์ŠคํŠธ๊ฐ€ ์‹คํŒจ๊ฐ€ ๋œฐ๊นŒ ..

def solution(s):
    answer = ""
    words = s.split()
    for i, word in enumerate(words):
        if i > 0:
            answer += " "
        word = word.lower()
        first_str = word[0].upper()
        word = first_str + word[1:]
        answer += word
    return answer

 

์ •๋‹ต์ฝ”๋“œ

def solution(s):
    answer = ''
    s = s.split(' ')
    for i in range(len(s)):
        # capitalize ๋‚ด์žฅํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ฒซ ๋ฌธ์ž๊ฐ€ ์•ŒํŒŒ๋ฒณ์ผ ๊ฒฝ์šฐ ๋Œ€๋ฌธ์ž๋กœ ๋งŒ๋“ค๊ณ 
        # ๋‘๋ฒˆ์งธ ๋ฌธ์ž๋ถ€ํ„ฐ๋Š” ์ž๋™์œผ๋กœ ์†Œ๋ฌธ์ž๋กœ ๋งŒ๋“ ๋‹ค
        # ์ฒซ ๋ฌธ์ž๊ฐ€ ์•ŒํŒŒ๋ฒณ์ด ์•„๋‹ˆ๋ฉด ๊ทธ๋Œ€๋กœ ๋ฆฌํ„ดํ•œ๋‹ค
        s[i]=s[i].capitalize()
    answer=' '.join(s)
    return answer
    

def solution2(s):
	return s.title()

 

์•„๋งˆ ์œ„ ์‹คํŒจ ์ฝ”๋“œ๋“ค์€ ๊ณต๋ฐฑ ๋ฌธ์ œ ๋•Œ๋ฌธ์— ์‹คํŒจ๊ฐ€ ์ผ์–ด๋‚˜๋Š” ๊ฒƒ ๊ฐ™์Œ 

์˜ˆ๋ฅผ ๋“ค์–ด ๊ณต๋ฐฑ์ด 2๊ฐœ ์ด์ƒ์ธ ๋ฌธ์ž์—ด์˜ ๊ณต๋ฐฑ๋„ ๋‹ค ์‚ด๋ ค์ค˜์•ผ ํ•˜๋Š”๋ฐ ๋ชป ์‚ด๋ ค์ค˜์„œ ๊ทธ๋Ÿฐ๋“ฏ ?

728x90