728x90
SMALL

public class Solution {
    public string solution(string s, int n) {
        string answer = "";
        char[] temp = s.ToCharArray();
        for(int i = 0; i < s.Length; ++i)
        {
            if ((temp[i] >= 'a' && temp[i] <= 'z')||(temp[i] >= 'A' && temp[i] <= 'Z'))
        {
            if (char.IsUpper(temp[i]))
            {
                 temp[i] = (char)((temp[i] + n - 'A') % 26 + 'A');
            }
            else
            {
                temp[i] = (char)((temp[i] + n - 'a') % 26 + 'a');
            }
        }
    }
         return new string(temp);
    }
}

 

/////

 

using System;
public class Solution {
    public string solution(string s, int n) {
        string answer = "";

        char[] c = s.ToCharArray();

        int temp = 0;
        for(int i = 0; i < s.Length; i++)
        {
            temp = c[i];

            if(temp == 32)
            {
            }
            else if(temp >= 65 && temp <= 90 && temp + n > 90 )
            {
                temp = temp + n - 26;
            }
            else if(temp >= 97 && temp <= 122 && temp + n > 122 )
            {
                temp = temp + n - 26;
            }
            else
            {
                temp += n;

            }
            answer += Convert.ToChar(temp).ToString();
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글