Created
May 3, 2020 06:07
-
-
Save DongguemYoo/f0d222933021d3fe566fd2a26cf16596 to your computer and use it in GitHub Desktop.
코딩테스트 연습문제 이상한 문자 만들기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ToCharArray로 변경했을때 다시 string으로 변환할때 주의 | |
//ToString으로 한다고 해서 들어가지 않음 | |
//new string()으로 새로 넣어줘야한다 | |
public class Solution { | |
public string solution(string s) | |
{ | |
string answer = ""; | |
string[] splits = s.Split(' '); | |
char[] tmp; | |
for (int i = 0; i < splits.Length; i++) | |
{ | |
tmp = splits[i].ToCharArray(); | |
for (int x = 0; x < tmp.Length; x++) | |
{ | |
if (x % 2 == 1) | |
{ | |
tmp[x] = char.ToLower(tmp[x]); | |
}else | |
tmp[x] = char.ToUpper(tmp[x]); | |
} | |
splits[i] = new string(tmp); | |
if (i == 0 || i == splits.Length) | |
{ | |
answer += splits[i]; | |
} | |
else | |
{ | |
answer += " "+splits[i]; | |
} | |
} | |
return answer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment