728x90
SMALL

using System;

public class Solution {
    public string solution(int age) {
        string answer = "";
        
        while(age != 0)
        {
            answer = (char)(age%10 + 97)+answer;
            age = age / 10;
        }   
        return answer;
    }
}

 

///

using System;
using System.Linq;

public class Solution {
    public string solution(int age) {
        string answer = string.Concat(age.ToString().Select(x => (char)(Convert.ToInt32(x.ToString()) + 97)));

        return answer;
    }
}

 

 

자바

 

class Solution {
    public String solution(int age) {
        String answer = "";
        String[] alpha = new String[]{"a","b","c","d","e","f","g","h","i","j"};
        while(age>0)
        {
            answer = alpha[age % 10] + answer;
            age /= 10;
        }
        return answer;
    }
}

 

 

class Solution {
    public String solution(int age) {
        StringBuilder sb = new StringBuilder();

        while(age > 0) 
        {
            sb.insert(0, (char) ((age % 10) + (int)'a'));
            age /= 10;
        }

        return sb.toString();
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int[] solution(int[] numbers, string direction) {
        int[] answer = new int[numbers.Length];
        
        if(direction == "right")
        {
            for(int i=0;i<numbers.Length-1;i++)
            {
                answer[0] = numbers[numbers.Length-1]; // 가장 오른쪽 배열을 0으로 이동
                answer[i+1] = numbers[i]; // 한 칸씩 이동
            }
        }
        else if(direction == "left")
        {
            for(int j=1;j<numbers.Length;j++)
            {
                answer[numbers.Length-1] = numbers[0]; // 맨 오른쪽 배열은 0번째로
                answer[j-1] = numbers[j]; // -1칸씩 이동
            }
        }
            
        return answer;
    }
}

 

파이썬

 

def solution(numbers, direction):
    return [numbers[-1]] + numbers[:-1] if direction == 'right' else numbers[1:] + [numbers[0]]

//////

def solution(numbers, direction):
    if direction == "right":
        answer = [numbers[-1]] + numbers[:len(numbers)-1]
    else:
        answer = numbers[1:] + [numbers[0]]
    return answer

 

자바

 

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

class Solution {
    public int[] solution(int[] numbers, String direction) {
        List<Integer> list = Arrays.stream(numbers).boxed().collect(Collectors.toList());

        if (direction.equals("right")) 
        {
            list.add(0, list.get(list.size() - 1));
            list.remove(list.size() - 1);
        } 
        else 
        {
            list.add(list.size(), list.get(0));
            list.remove(0);
        }
        return list.stream().mapToInt(Integer::intValue).toArray();
    }
}

 

 

import java.util.*;

class Solution {
    public ArrayList solution(int[] numbers, String direction) {
        ArrayList<Integer> answer = new ArrayList<Integer>();

        for(int i=0; i<numbers.length; i++)
        {
            answer.add(numbers[i]);
        }

        int targetValue = 0;

        if(direction.equals("right"))
        {
            answer.add(0, numbers[numbers.length-1]);
            answer.remove(answer.size()-1);

        }
        else
        {
            answer.add(numbers[0]);
            answer.remove(0);
        }

        return answer;
    }
}

 

 

class Solution {
    public int[] solution(int[] numbers, String direction) {
        int[] answer = new int[numbers.length];

        if(direction.equals("right"))
        {
            for(int i = 0; i<numbers.length; i++)
            {
                if(i==numbers.length-1)
                {
                    answer[0] = numbers[i];
                }
                else answer[i+1] = numbers[i];
            }
        }
        else
        {
            for(int i = 1; i<numbers.length; i++)
            {
                answer[i-1] = numbers[i];
            }
            
            answer[numbers.length-1] = numbers[0];
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Collections.Generic;

public class Solution {
    public int solution(int[] numbers) {
        int max = 0;
        int max1 = -999999999;
        
        for(int i=0;i<numbers.Length;i++)
        {
            for(int j=0;j<numbers.Length;j++)
            {
               if(i == j)
               {
                   continue;
               }
               else
               {
                   max = (numbers[i])*(numbers[j]);
                  if(max > max1)
                  {
                      max1 = max;
                  }
               }
            }
        }
        
        return max1;
    }
}

 

// 1번 방법 Linq없이 그냥 하는 법

// 7번째 테스트에서 에러가 나는데 아마 [9999, -10000] 뭐 이런 케이스인 거 같다. max1을 -999999999로 하니까 에러가 안나기는 함.

//

using System;
using System.Collections.Generic;
using System.Linq;

 

public class Solution {
    public int solution(int[] numbers) {
        List<int> list = new List<int>();
        
        for(int i = 0; i < numbers.Length; i++)
        {
            for(int j = 0; j < numbers.Length; j++)
            {            
                if(i == j)
                {
                    continue;
                }
                else
                {
                    list.Add(numbers[i] * numbers[j]);
                }
            }
        }
        return list.Max();
    }
}

 

// 링크를 사용하는 방법. 코드는 이게 더 쉽다.

using System;

public class Solution {
    public int solution(int[] numbers) {
        int maxLen = numbers.Length-1;
        Array.Sort(numbers);
        return (int)MathF.Max(numbers[0]*numbers[1], numbers[maxLen]*numbers[maxLen-1]);
    }
}

 

 

///

자바

 

import java.util.*;

class Solution {
    public int solution(int[] numbers) {
        int len = numbers.length;
        Arrays.sort(numbers);
        return Math.max(numbers[0] * numbers[1], numbers[len - 2] * numbers[len - 1]);
    }
}

 

파이썬

 

def solution(numbers):
    numbers = sorted(numbers)
    return max(numbers[0] * numbers[1], numbers[-1]*numbers[-2])
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Collections.Generic;

public class Solution {
    public int[] solution(int n) {
        List<int> List = new List<int>();
        for(int i=1;i<n+1;i++)
        {
            if(n%i == 0)
            {
                List.Add(i);
            }
        }
        int[] answer = List.ToArray();
        return answer;
    }
}

 

파이썬

 

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

 

자바

 

import java.util.*;

class Solution {
    public int[] solution(int n) {
        List<Integer> list = new ArrayList<>();

        for (int i = 1; i <= n / 2; i++) 
        {
            if (n % i == 0) 
            {
                list.add(i);
            }
        }

        list.add(n);

        return list.stream().mapToInt(e -> e).toArray();
    }
}

 

 

import java.util.stream.IntStream;
import java.util.Arrays;

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

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Linq;

public class Solution {
    public int[] solution(int[] array) {
        int[] answer = new int[2] {array.Max(), Array.IndexOf(array, array.Max())};
        return answer;
    }
}

        //array.Max()는 배열 원소중 가장 큰수를 반환. Array.IndexOf는 지정한 개체를 검색하여 같은 원소가 있으면 그 인덱스 번호를 반환함

 

파이썬

 

def solution(array):
    val = max(array)
    return [val, array.index(val)]

 

자바

 

class Solution {
    public int[] solution(int[] array) {
        int[] answer = new int[2];

        for(int i=0;i<array.length;i++) 
        {
            if(array[i] > answer[0]) 
            {
                answer[0] = array[i];
                answer[1] = i;
            }
        }

        return answer;
    }
}

 

 

class Solution {
    public int[] solution(int[] array) {
        int max = 0;
        int maxIndex = -1;
        
        for (int i = 0; i < array.length; i++) 
        {
            if (max < array[i]) 
            {
                max = array[i];
                maxIndex = i;
            }
        }
        
        int[] answer = {max, maxIndex};
        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int[] box, int n) {
        int answer = 0;
        answer += box[0]/n;
        answer *= box[1]/n;
        answer *= box[2]/n;
        return answer;
    }
}

 

파이썬

 

def solution(box, n):
    x, y, z = box
    return (x // n) * (y // n) * (z // n )

 

자바

 

class Solution {
    public int solution(int[] box, int n) {
        int answer = 1;

        answer *= box[0]/n;
        answer *= box[1]/n;
        answer *= box[2]/n;

        return answer;
    }
}

 

 

 

자바

 

 

class Solution {
    public int solution(int[] box, int n) {
        int answer = 1;

        answer *= box[0]/n;
        answer *= box[1]/n;
        answer *= box[2]/n;

        return answer;
    }
}

 

 

class Solution {
    public int solution(int[] box, int n) {
        int answer = 0;
        
        for(int length : box)
        {
            if(answer == 0)
            {
                answer = length / n;
            }
            else
            {
                answer *= length / n;
            }
        }
        return answer;
    }
}

 

 

class Solution {
    public int solution(int[] box, int n) {
        int answer = (box[0] / n) * (box[1] / n) * (box[2] / n);

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public string solution(string rsp) {
        string answer = "";
        // 2 > 0
        // 0 > 5
        // 5 > 2
        for(int i=0;i<rsp.Length;i++)
        {
            if(rsp[i].ToString() == "2")
            {
                answer += "0";
            }
            else if(rsp[i].ToString() == "0")
            {
                answer += "5";
            }
            else
            {
                answer += "2";
            }
        }
        
        return answer;
    }
}

 

파이썬

 

////

def solution(rsp):
    rsp =rsp.replace('2','s')
    rsp =rsp.replace('5','p')
    rsp =rsp.replace('0','r')
    rsp =rsp.replace('r','5')
    rsp =rsp.replace('s','0')
    rsp =rsp.replace('p','2')
    return rsp

/////

 

def solution(rsp):
    answer = ''
    for i in list(map(int, rsp)):
        if i == 0:
            answer += str(5)
        elif i == 2:
            answer += str(0)
        else:
            answer += str(2)
    return answer

 

 

자바

 

 

class Solution {
    public String solution(String rsp) {
        char[] cRsp = rsp.toCharArray();
        StringBuilder answer = new StringBuilder();

        for(int i=0; i < cRsp.length; i++) 
        {
            switch(cRsp[i]) 
            {
                case '0' :
                    answer.append("5");
                    break;
                case '2' :
                    answer.append("0");
                    break;
                case '5' :
                    answer.append("2");
                    break;
            }
        }
        
        return answer.toString();

    }
}

 

 

class Solution {
    public String solution(String rsp) {
        String answer = "";
        String[] arr = rsp.split("");
        
        for(int i=0;i < arr.length; i++) 
        {
            if(arr[i].equals("2")) 
              answer += "0";
            else if(arr[i].equals("0")) 
              answer += "5";
            else
              answer += "2";
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Collections.Generic;

public class Solution {
    public int[] solution(string my_string) { 
        List<int> List = new List<int>();
        
        for(int i = 0; i < my_string.Length; i++)
        {  
            if(Char.IsDigit(my_string[i]) == true)
            {
                List.Add((int)my_string[i] - 48);
            }
        }
        
        int[] answer = List.ToArray();
        Array.Sort(answer);
        return answer;
    }
}

 

///

 

using System;
using System.Collections.Generic;
using System.Linq;

public class Solution {
    public int[] solution(string my_string) { 

        int[] answer = my_string.Where(x => char.IsNumber(x)).Select(x => Convert.ToInt32(x.ToString())).OrderBy(x => x).ToArray();

        Array.Sort(answer);
        return answer;
    }
}

 

파이썬

 

def solution(my_string):
    answer = []
    for i in my_string:
        if i.isdigit():
            answer.append(int(i))
    answer.sort()
    return answer

////

 

def solution(my_string):
    return sorted([int(c) for c in my_string if c.isdigit()])

 

//////

자바

//////

import java.util.*;

class Solution {
    public int[] solution(String my_string) {
        my_string = my_string.replaceAll("[a-z]","");
        int[] answer = new int[my_string.length()];

        for(int i =0; i<my_string.length(); i++)
        {
            answer[i] = my_string.charAt(i) - '0';
        }

        Arrays.sort(answer);

        return answer;
    }
}

 

 

import java.util.*;

class Solution {
    public int[] solution(String myString) {
        return Arrays.stream(myString.replaceAll("[A-Z|a-z]", "").split("")).sorted().mapToInt(Integer::parseInt).toArray();
    }
}
728x90

설정

트랙백

댓글