<문제>
문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 리턴하는 함수, solution을 완성하세요.
public class Solution {
public string solution(string s) {
string answer = "";
string[] word = s.Split(new char[] { ' ' });
for (int i = 0; i < word.Length; i++)
{
char[] str = word[i].ToCharArray();
if(i>0)
answer = answer + " ";
for (int j=0; j<str.Length;j++)
{
if (j % 2 == 0)
if(97<=str[j]&&str[j]<=122) //str[j]가 소문자면
answer = answer + (char)(str[j]-32); // 대문자로 변환해서 추가
else //str[j] 대문자면
answer = answer + str[j]; // 추가
else
if(97<=str[j]&&str[j]<=122)
answer = answer + str[j];
else
answer = answer + (char)(str[j]+32);
}
}
return answer;
}
}

'코딩연습 > 프로그래머스 코딩테스트' 카테고리의 다른 글
| [프로그래머스] Level1 두 개 뽑아서 더하기 (0) | 2021.02.17 |
|---|---|
| [프로그래머스]Level1 시저암호 (0) | 2021.02.16 |
| [프로그래머스]Level1 모의고사 (0) | 2021.02.04 |
| [프로그래머스]Level1 평균구하기 (0) | 2021.02.04 |
| [프로그래머스]Level1 자릿수더하기 (0) | 2020.10.08 |