๋ฌธ์ ํฌ์ธํธ : ๋ชจ๋ ๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ณํํ๋ค.
ํ์ด์ฌ์ ๊ฒฝ์ฐ๋ .lower()
์๋ฐ์ ๊ฒฝ์ฐ๋ toLowerCase() ๋ฅผ ์ฌ์ฉ
๊ทธ๋ฆฌ๊ณ ์ฒซ ๋ฌธ์๋ง ์ํ๋ฒณ์ด๋ฉด ๋๋ฌธ์๋ก ์ง์ ๋ง๋ค์ด์ฃผ๊ณ , ๋๋จธ์ง๋ ๊ณต๋ฐฑ ๋ค์์ ์ค๋ ๋ฌธ์๊ฐ ์ํ๋ฒณ์ธ ๊ฒฝ์ฐ์๋ง ๋๋ฌธ์๋ก ๋ณํ์์ผ์ค๋ค.
์๋ฐ ์ฝ๋
import java.util.*;
class Solution {
public String solution(String s) {
String answer = "";
s=s.toLowerCase();
StringBuilder sb = new StringBuilder();
for(int i=0;i<s.length();i++){
char text = s.charAt(i);
if(i==0){
if(isAlpha(text)){
sb.append((char)(text-'a'+'A'));
}else{
sb.append(text);
}
}else{
if(s.charAt(i-1)==' ' && isAlpha(text)){
sb.append((char)(text-'a'+'A'));
}else{
sb.append(text);
}
}
}
return sb.toString();
}
public boolean isAlpha(char text){
if('a' <= text && text <= 'z'){
return true;
}
return false;
}
}
ํ์ด์ฌ ์ฝ๋
# ์ฒซ ๋ฌธ์๊ฐ ๋๋ฌธ์์ด๊ณ ๊ทธ ์ธ๋ ์๋ฌธ์
def solution(s):
s = s.lower()
s = list(s)
if s[0].isalpha():
s[0]=s[0].upper()
for i in range(1,len(s)):
if s[i-1]==' ' and s[i].isalpha():
s[i]=s[i].upper()
answer = ''.join(s)
return answer