728x90
SMALL

using System;

public class Solution {
    public string solution(string cipher, int code) {
        string answer = "";
        
        for(int i=0;i<cipher.Length;i++)
        {
            if(i%code == 0 && code+i-1 < cipher.Length && i != 0) //code로 나뉘어지고, cipher.Length+1보다 작은 범위 내에서 출력.
            {
                answer += cipher[code+i-1];
            }
        }
        return answer;
    }
}

 

////

 

using System;

public class Solution {
    public string solution(string cipher, int code) {
        string answer = "";
        for(int i=code-1;i<cipher.Length;i+=code)
        {
            answer+=cipher[i];
        }
        return answer;
    }
}

 

파이썬

 

def solution(cipher, code):
    answer = cipher[code-1::code]
    return answer

 

 

자바

 

 

import java.util.*;
class Solution {
    public String solution(String cipher, int code) {
        String[] arr = cipher.split("");
        StringBuilder sb = new StringBuilder();
        int x = code-1;
        
        while(x < arr.length) 
        {
            sb.append(arr[x]);
            x += code;
        }

        return sb.toString();
    }
}

 

 

class Solution {
    public String solution(String cipher, int code) {
        String answer = "";
        
        for(int i=code-1; i<cipher.length(); i+=code)
        {
            answer += cipher.substring(i, i+1);
        }
        
        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public string solution(string my_string) {
        string answer = "";
        for(int i = 0; i < my_string.Length; i++)
        {
            if(Char.IsLower(my_string[i]) == true) //소문자면 대문자로 바꾸기
            {
                answer += Char.ToUpper(my_string[i]);
            }
            else
            {
                answer += Char.ToLower(my_string[i]);
            }
        }
        return answer;
    }
}

 

///

 

//answer = my_string.ToUpper();
//answer2 = my_string.ToLower();
전부다 대문자 혹은 소문자로 바꾸는 방법은 알았는데 Char.ToLower, Char.ToUpper이런 거는 몰랐다.

 

using System;

public class Solution {
    public string solution(string my_string) {
        string answer = "";

        foreach (var it in my_string)
        {
            if ('a' <= it && it <= 'z')
            {
                answer += it.ToString().ToUpper();
            }
            else
            {
                answer += it.ToString().ToLower();
            }
        }

        return answer;
    }
}

  

파이썬

 

def solution(my_string):
    answer = ''

    for i in my_string:
        if i.isupper():
            answer+=i.lower()
        else:
            answer+=i.upper()
    return answer

 

 

자바

 

class Solution {
    public String solution(String my_string) {
        String answer = "";
        
        for(int i=0; i<my_string.length(); i++)
        {
            char c = my_string.charAt(i);
            
            if(Character.isUpperCase(c))
            {
                answer += String.valueOf(c).toLowerCase();
            }
            else
            {
                answer += String.valueOf(c).toUpperCase();
            }
        }
        return answer;
    }
}

 

 

class Solution {
    public String solution(String my_string) {
        String answer = "";

        for (int i = 0; i < my_string.length(); i++) 
        {
            int num = (int)my_string.charAt(i);

            if (num >= 65 && num <= 90) 
              answer += (char)(num + 32) + "";
            else 
              answer += (char)(num - 32) + "";
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int n, int t) {
        
        for(int i=1;i<=t;i++)
        {
            n = 2*n;
        }
        
        return n;
    }
}

 

파이썬

////

def solution(n, t):
    answer = 2**t * n
    return answer

 

비트연산

////

 

def solution(n, t):
    return n << t

 

 

자바

 

 

class Solution {
    public int solution(int n, int t) {
        int answer = 0;

        answer = n << t;

        return answer;
    }
}

 

 

class Solution {
    public int solution(int n, int t) {
        int answer = n;
        
        for(int i=1; i<=t; i++)
        {
            answer *= 2;
        }
        return answer;
    }
}

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int[] solution(int n, int[] numlist) {
        int length = 0;
        int length2 = 0;
        
        for(int i=0;i<numlist.Length;i++)
        {
            if(numlist[i]%n == 0)
            {
                length2++;
            }
        }
        int[] answer = new int[length2];

/// 배열의 길이 정의하기
        
        for(int i=0;i<numlist.Length;i++)
        {
            if(numlist[i]%n == 0)
            {
                answer[length] = numlist[i];
                length++;
            }
        }
    
        return answer;
    }
}

 

//리스트를 모른다고 생각했을 때 노가다 방식으로

 

//List를 사용했을 때

 

using System;
using System.Collections.Generic;

public class Solution {
    public int[] solution(int n, int[] numlist) {
        int[] answer = new int[] {};
        List<int> insList = new List<int>();

        for(int i = 0; i < numlist.Length; i++)
        {
            if(numlist[i]%n == 0)
            {
                insList.Add(numlist[i]);
            }
        }
        
        answer = insList.ToArray();
        return answer;
    }
}

 

파이썬

 

def solution(n, numlist):
    answer = [i for i in numlist if i%n==0]
    return answer

 

 

자바

 

 

import java.util.ArrayList;

class Solution {
    public int[] solution(int n, int[] numlist) {
        ArrayList<Integer> List = new ArrayList<>();
        
        for(int i = 0;i < numlist.length; i++)
        {
            if(numlist[i] % n == 0)
            {
                List.add(numlist[i]);
            }
        }
        
        int[] answer = new int[List.size()];
        for(int i = 0; i< List.size(); i++)
        {
            answer[i] = List.get(i);
        }
        
        return answer;
    }
}

 

 

import java.util.List;
import java.util.ArrayList;

class Solution {
    public int[] solution(int n, int[] numlist) {
        List<Integer> answer = new ArrayList<>();
        
        for(int num : numlist)
        {    
            if(num % n == 0)
            {
                answer.add(num);
            }
        }
        
        return answer.stream().mapToInt(x -> x).toArray();
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int hp) {
        int answer = 0;
        //장군개미 5
        //병정개미 3
        //일개미 1
        while(hp >= 5)
        {
            hp = hp-5;
            answer++;
        }
        
        while(hp >= 3)
        {
            hp = hp-3;
            answer++;
        }
            
        while(hp >= 1)
        {
            hp = hp-1;
            answer++;
        }
        
        return answer;
    }
}

 

/// 이러면 시간 개 오래 걸린다.

 

using System;

public class Solution {
    public int solution(int hp) {
        int answer = 0;

        int ant_5 = hp / 5;
        int ant_3 = (hp % 5) / 3  ;
        int ant_1 = (hp % 5) % 3 / 1 ;

        return ant_5 + ant_3 + ant_1;
    }
}

 

파이썬

 

def solution(hp):    
    return hp // 5 + (hp % 5 // 3) + ((hp % 5) % 3)

 

 

자바

 

 

class Solution {
    public int solution(int hp) {
        int answer = hp / 5;
        hp %= 5;

        answer += hp / 3;
        hp %= 3;

        answer += hp / 1;

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public string solution(string my_string) {
        string answer = "";
        
        answer = my_string.Replace("a", "");
        answer = answer.Replace("e", "");
        answer = answer.Replace("i", "");
        answer = answer.Replace("o", "");
        answer = answer.Replace("u", "");
        return answer;
    }
}

 

// 모음은 꼴랑 다섯 개 밖에 없으니까 이렇게 노가다로 해도 되긴 하는데

//////

 

using System;
using System.Text.RegularExpressions;

public class Solution {
    public string solution(string my_string) {
        string answer = "";
        
        string[] arr = my_string.Split('a', 'e', 'i', 'o', 'u');
        for(int i = 0; i < arr.Length; i++)
        {
            answer += arr[i];
        }
        
        // Regex.Replace를 이용한 다른 풀이
        // answer = Regex.Replace(my_string, "a|e|i|o|u", "");

        return answer;
    }
}

 

파이썬

 

def solution(my_string):
    vowels = ['a','e','i','o','u']
    for vowel in vowels:
        my_string = my_string.replace(vowel, '')
    return my_string

 

//////

def solution(my_string):
    return "".join([i for i in my_string if not(i in "aeiou")])

 

 

자바

 

 

class Solution {
    public String solution(String my_string) {
        String answer = "";

        answer = my_string.replaceAll("[aeiou]", "");

        return answer;
    }
}

 

 

 

class Solution {
    public String solution(String my_string) {
        String[] vowels = new String[]{"a", "e", "i", "o", "u"};
        
        for(String vowel : vowels)
        {
            if(my_string.contains(vowel))
            {
                my_string = my_string.replace(vowel, "");
            }
        }
        
        return my_string;
    }
}

 

 

class Solution {
    public String solution(String my_string) {
        String answer = "";
        answer = my_string.replaceAll("[a,e,i,o,u]","");

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Text.RegularExpressions;

public class Solution {
    public int solution(string my_string) {
        int answer = 0;
              
        for(int i = 0; i < my_string.Length; i++)
        {
            // IsDigit은 string에 문자가 10진수인지 판별하고 참이면 True를 반환  
            if(Char.IsDigit(my_string[i]) == true)
            {
                answer += (int)my_string[i] - 48; // ASCII 코드 상에서 문자1의 수치가 49여서 거기에서 48을 빼주는 방식으로 한다.
            }
        }
        return answer;
    }
}

 

////

using System;
using System.Linq;

public class Solution {
    public int solution(string my_string) {
        int answer = my_string.Where(x => char.IsNumber(x)).Sum(x => Convert.ToInt32(x.ToString()));

        return answer;
    }
}

 

파이썬

 

def solution(my_string):
    answer = 0
    for i in my_string:
        try:
            answer = answer + int(i)
        except:
            pass

    return answer

///////////

def solution(my_string):
    return sum(int(i) for i in my_string if i.isdigit())

 

자바

 

 

import java.util.regex.Pattern;
import java.util.regex.Matcher;

class Solution {
    public int solution(String my_string) {
        int answer = 0;
        String pattern = "^[0-9]*$";
        String[] list = my_string.split("");

        for(int i = 0; i < list.length; i ++) 
        {
            if(Pattern.matches(pattern,list[i])) 
            {
                answer += Integer.parseInt(list[i]);
            }
        }
        return answer;
    }
}

 

 

class Solution {
    public int solution(String my_string) {
        int answer = 0;
        String str = my_string.replaceAll("[^0-9]","");

        for(char ch : str.toCharArray()) 
        {
            answer += Character.getNumericValue(ch);
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for(int i=1;i<=n;i++)
        {
            if(n%i == 0)
            {
                answer++;
            }
        }
        return answer;
    }
}

 

 

/////

자바

 

class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for(int i = 1; i <= n; i++)
        {
            if(n % i == 0)
            {
                answer++;
            }
        }
        
        return answer;
    }
}

 

 

import java.util.stream.IntStream;

class Solution {
    public int solution(int n) {
        return (int) IntStream.rangeClosed(1, n).filter(i -> n % i == 0).count();
    }
}

 

파이썬

 

 

def solution(n):
    answer =0 
    for i in range(n):
        if n % (i+1) ==0:
            answer +=1
    return answer
728x90

설정

트랙백

댓글