728x90
SMALL

using System;

public class Solution {
    public string solution(string[] survey, int[] choices) {
        string answer = "";
        int[] type = new int[8];
        // R T C F J M A N
        string[] types = new string[8] {"R", "T", "C", "F", "J", "M", "A", "N"};
        
        for(int i = 0;i<survey.Length;i++)
        {
            if((survey[i])[0] == 'A')
            {
                if(choices[i] >= 4)
                {
                    type[7] += choices[i]-4;
                }
                else
                {
                    type[6] += 4-choices[i];
                }
            }
            else if((survey[i])[0] == 'N')
            {
                if(choices[i] >= 4)
                {
                    type[6] += choices[i]-4;
                }
                else
                {
                    type[7] += 4-choices[i];
                }
            }
            else if((survey[i])[0] == 'C')
            {
                if(choices[i] >= 4)
                {
                    type[3] += choices[i]-4;
                }
                else
                {
                    type[2] += 4-choices[i];
                }
            }
            else if((survey[i])[0] == 'F')
            {
                if(choices[i] >= 4)
                {
                    type[2] += choices[i]-4;
                }
                else
                {
                    type[3] += 4-choices[i];
                }
            }
            else if((survey[i])[0] == 'M')
            {
                if(choices[i] >= 4)
                {
                    type[4] += choices[i]-4;
                }
                else
                {
                    type[5] += 4-choices[i];
                }
            }
            else if((survey[i])[0] == 'J')
            {
                if(choices[i] >= 4)
                {
                    type[5] += choices[i]-4;
                }
                else
                {
                    type[4] += 4-choices[i];
                }
            }
            else if((survey[i])[0] == 'R')
            {
                if(choices[i] >= 4)
                {
                    type[1] += choices[i]-4;
                }
                else
                {
                    type[0] += 4-choices[i];
                }
            }
            else if((survey[i])[0] == 'T')
            {
                if(choices[i] >= 4)
                {
                    type[0] += choices[i]-4;
                }
                else
                {
                    type[1] += 4-choices[i];
                }
            }
        }
        
        for(int i = 0;i<4;i++)
        {
            if(type[2*i] >= type[2*i+1])
            {
                answer += types[2*i];
            }
            else
            {
                answer += types[2*i+1];
            }
        }

        return answer;
    }
}

 

 

/// 완전 노가다로 풀었다.

 

딕셔너리를 활용하는 거였다.

 

using System;
using System.Collections.Generic;

public class Solution {
    public string solution(string[] survey, int[] choices) {

        Dictionary<string, int> result = new Dictionary<string, int>
        {
            {"R",0}, {"T",0}, {"C",0}, {"F",0}, {"J",0}, {"M",0}, {"A",0}, {"N",0}
        };

        for (int i=0; i<survey.Length; i++)
        {               
            int values=0;
            string valueName="";

            if (choices[i] >= 4)
            {
                values = 4-choices[i];
                valueName=survey[i][0].ToString();
            }
            else
            {
                values = choices[i]-4;
                valueName=survey[i][1].ToString();
            }

            result[valueName] += values;
        }
        return MBTI(result);
    }

    public string MBTI(Dictionary<string, int> result)
    {
        string answer = result["R"] < result["T"] ? "T" : "R";
        answer += result["C"] < result["F"] ? "F" : "C";
        answer += result["J"] < result["M"] ? "M" : "J";
        answer += result["A"] < result["N"] ? "N" : "A";
        // 점수가 낮을 수록(마이너스 절대값이 클 수록) 선택되도록 설계
        return answer;        
    }
}

 

 

 

파이썬

 

 

def solution(survey, choices):

    my_dict = {"RT":0,"CF":0,"JM":0,"AN":0}
    for A,B in zip(survey,choices):
        if A not in my_dict.keys():
            A = A[::-1]
            my_dict[A] -= B-4
        else:
            my_dict[A] += B-4

    result = ""
    for name in my_dict.keys():
        if my_dict[name] > 0:
            result += name[1]
        elif my_dict[name] < 0:
            result += name[0]
        else:
            result += sorted(name)[0]

    return result

 

자바

//////

import java.util.HashMap;

class Solution {
    public String solution(String[] survey, int[] choices) {
        String answer = "";
        HashMap<Character, Integer> map = new HashMap<>();
        map.put('R', 0);map.put('T', 0);
        map.put('C', 0);map.put('F', 0);
        map.put('J', 0);map.put('M', 0);
        map.put('A', 0);map.put('N', 0);

        for (int i = 0; i < survey.length; i++) {
            if (choices[i] > 4)
                map.put(survey[i].charAt(1), map.get(survey[i].charAt(1)) + choices[i] - 4);
            else if (choices[i] < 4) {
                map.put(survey[i].charAt(0), map.get(survey[i].charAt(0)) + 4 - choices[i]);
            }
        }


        if (map.get('R') >= map.get('T'))
            answer = "R";
        else
            answer = "T";

        if (map.get('C') >= map.get('F'))
            answer += "C";
        else
            answer += "F";

        if (map.get('J') >= map.get('M'))
            answer += "J";
        else
            answer += "M";

        if (map.get('A') >= map.get('N'))
            answer += "A";
        else
            answer += "N";

        return answer;
    }
}

 

 

import java.util.HashMap;

class Solution {
    public String solution(String[] survey, int[] choices) {
        String answer = "";
        char [][] type = {{'R', 'T'}, {'C', 'F'}, {'J', 'M'}, {'A', 'N'}};
        int [] score = {0, 3, 2, 1, 0, 1, 2, 3};
        HashMap<Character, Integer> point = new HashMap<Character, Integer>();

        // 점수 기록할 배열 초기화 
        for (char[] t : type) {
            point.put(t[0], 0);
            point.put(t[1], 0);
        }

        // 점수 기록 
        for (int idx = 0; idx < choices.length; idx++){
            if(choices[idx] > 4){
                point.put(survey[idx].charAt(1), point.get(survey[idx].charAt(1)) + score[choices[idx]]);
            } else {
                point.put(survey[idx].charAt(0), point.get(survey[idx].charAt(0)) + score[choices[idx]]);
            }
        }

        // 지표 별 점수 비교 후 유형 기입
        for (char[] t : type) {
            answer += (point.get(t[1]) <= point.get(t[0])) ? t[0] : t[1];
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int[] number) {
        int answer = 0;

        for(int i = 0;i<number.Length;i++)
        {
            for(int j = i+1;j<number.Length;j++)
            {
                for(int k = j+1;k<number.Length;k++)
                {
                    if(number[i]+number[j]+number[k]==0)
                    {
                        answer++;
                    }
                }
            }
        }
        
        return answer;
    }
}

 

// number의 길이가 그렇게 길지 않아서 걍 포문을 돌렸다.

 

 

 

파이썬

////

 

 

def solution(number):
    answer = 0
    l = len(number)
    for i in range(l-2):
        for j in range(i+1, l-1):
            for k in range(j+1, l):
                # print(number[i],number[j],number[k])
                if number[i]+number[j]+number[k] == 0:
                    answer += 1           
    return answer

 

////

from itertools import combinations
def solution(number):
    answer = 0
    for c in combinations(range(len(number)), 3):
        if sum([number[int(i)] for i in c]) == 0:
            answer += 1
    return answer

 

 

자바

////

 

 

class Solution {
    public int solution(int[] number) {
        int answer = 0;

        for(int i=0; i<number.length-2; i++)
        {
            for(int j=i+1; j<number.length-1; j++)
            {
                for(int k=j+1; k<number.length; k++)
                {
                    if(number[i]+number[j]+number[k]==0) 
                      answer++;
                }
            }
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

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

 

파이썬

////

 

def solution(n):

    if not 3 <= n <= 1000000 :
        return False

    answer = 2
    while True :
        if n % answer == 1 :
            break
        else :
            answer += 1

    return answer

 

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

 

자바

/////

 

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

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int[] absolutes, bool[] signs) {
        int answer = 0;
        
        for(int i = 0;i<absolutes.Length;i++)
        {
            if(signs[i] == true)
            {
                answer += absolutes[i];
            }
            else
            {
                answer += -1 * absolutes[i];
            }
        }
        
        return answer;
    }
}

 

////////

 

파이썬

 

def solution(absolutes, signs):
    answer=0
    for absolute,sign in zip(absolutes,signs):
        if sign:
            answer+=absolute
        else:
            answer-=absolute
    return answer

 

자바

//////

 

 

class Solution {
    public int solution(int[] absolutes, boolean[] signs) {
        int answer = 0;
        
        for (int i=0; i<signs.length; i++)
            answer += absolutes[i] * (signs[i]? 1: -1);
        
        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Linq;

public class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        Array.Sort(citations);
        Array.Reverse(citations);
        
        for(int i = 0;i<citations.Length;i++)
        {
            if(citations[i] >= i+1)
            {
                answer++;
            }
        }
        
        return answer;
    }
}

 

/////////////

 

//이건 아무리 봐도 설명이 부실했다. 예에 나온 것처럼 [3, 0, 6, 1, 5] 일때 인용이 많은 순서대로 정렬한 [6,5,3,1,0]에서 0번째 인덱스는 1보다 커야하고 1번째 인덱스는 2보다 커야하는 식으로

 

///내림차순으로 정렬된 어레이에서 처음부터 i 번째 어레이의 인덱스가 i+1보다 크지 않은 첫 번째 경우가 나올 때까지의 갯수를 구하는 건데 약간 설명이 애매하게 돼 있다. 

 

 

파이썬

 

def solution(citations):
    citations.sort(reverse=True)
    answer = max(map(min, enumerate(citations, start=1)))
    return answer

 

/////

 

 

def solution(citations):
    citations = sorted(citations)
    l = len(citations)
    for i in range(l):
        if citations[i] >= l-i:
            return l-i
    return 0

 

 

자바

 

 

import java.util.Arrays;

class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        Arrays.sort(citations);
        
        for(int i=0; i<citations.length; i++)
        {
            int smaller = Math.min(citations[i], citations.length-i);
            answer = Math.max(answer, smaller);
        }
        
        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int[] solution(int[] numbers) {
        int[] answer = new int[numbers.Length];
        
        for(int i=0;i<numbers.Length;i++)
            answer[i] = numbers[i] * 2;
        return answer;
    }
}

 

/////

 

파이썬

 

/////

def solution(numbers):
    return [num*2 for num in numbers]

 

자바

 

class Solution {
    public int[] solution(int[] numbers) {
        int[] answer = {};
        answer = new int[numbers.length];
        
        for(int i=0; i<answer.length; i++)
        {
            answer[i] = numbers[i]*2;
        }
        
        return answer;
    }
}

 

 

import java.util.*;

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

        for(int num : numbers)
        {
            answer.add(num*2);
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int num1, int num2) {
        int answer = num1/num2;
        return answer;
    }
}

 

 

파이썬

def solution(num1, num2):
    return num1 // num2

////////

solution = int.__floordiv__

 

JAVA

 

class Solution {
    public int solution(int num1, int num2) {
        return num1/num2;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int[] solution(string s) {
        int[] answer = new int[2]; 
        int index = 0;
        int i = 0;
        
        while(s != "1")
        {
            int length = s.Length;
            s = s.Replace("0", "");
            index++;
            length = length - s.Length;
            i += length;
            s = Convert.ToString(s.Length, 2);
        }
        
        answer[0] = index;
        answer[1] = i;
        
        return answer;
    }
}

 

728x90

설정

트랙백

댓글