728x90
SMALL

using System;

public class Solution {
    public int solution(int[] array) {
        int answer = 0;
        
        for(int i=0;i<array.Length;i++)
        {
            while(array[i]>10)
            {
                if(array[i]%10 == 7)
                {
                    answer++;
                }
                array[i] = array[i]/10;
            }
            
            if(array[i]%10 == 7)
            {
                answer++;
            }
        }
        
        return answer;
    }
}

 

///

 

using System;

public class Solution {
    public int solution(int[] array) {
        int answer = 0;
        
        foreach(int i in array)
        {
            int temp = i;
            while(temp > 0)
            {
                if(temp%10 == 7)
                    answer++;
                    
                temp /= 10;
            }
        }
        return answer;
    }
}

 

파이썬

/////

 

def solution(array):
    return str(array).count('7')

 

자바

//////

 

class Solution {
    public int solution(int[] array) {
        int answer = 0;
        
        for(int a : array)
        {
            while(a != 0)
            {
                if(a % 10 == 7)
                {
                    answer++;
                }
                
                a /= 10;
            }
        }
        return answer;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

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

public class Solution {
    public string solution(string s) {
        string answer = "";
        int count = 0;
        int j =0;
        
        for(int i=0;i<s.Length;i++)
        {
            for(j=0;j<s.Length;j++)
            {
                if(s[i] == s[j])
                {
                    count++;
                }    
            }
            
            if(count == 1)
                {
                    answer += s[i];
                }
                count = 0;    
        }
        answer = string.Concat(answer.OrderBy(x => x));   
        return answer;
    }
}

 

//뭔가 이상하다

 

using System;
using System.Linq;

public class Solution {
    public string solution(string s) {
        string answer = string.Concat(s.Where(x => s.Count(o => o == x) == 1).OrderBy(x => x));
        return answer;
    }
}

 

파이썬

//////

 

def solution(s):
    answer = ''
    for c in 'abcdefghijklmnopqrstuvwxyz':
        if s.count(c) == 1:
            answer += c
    return answer

 

///////////

 

def solution(s):
    answer = "".join(sorted([ ch for ch in s if s.count(ch) == 1]))
    return answer

 

자바

//////

 

class Solution {
    public String solution(String s) {
        int[] alpha = new int[26];
        
        for(char c : s.toCharArray())
        {
            alpha[c - 'a']++;
        }

        StringBuilder answer = new StringBuilder();
        
        for(int i = 0; i < 26; i++)
        {
            if(alpha[i] == 1)
            {
                answer.append((char)(i + 'a'));
            }
        }
        return answer.toString();
    }
}

 

 

import java.util.*;

class Solution {
    public String solution(String s) {

        HashSet<String> set = new HashSet<>();

        for (int i = 0; i < s.length(); i++) {
            String replace = s.replace(s.charAt(i) + "", "");
            if(s.length() - replace.length() == 1){
                set.add(s.charAt(i)+"");
            }
        }
        ArrayList<String> list = new ArrayList<>(set);
        Collections.sort(list);
        return String.join("", list);
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

public class Solution {
    public int[] solution(int[] emergency) {
        int[] answer = new int[emergency.Length];
        
        for(int i = 0; i < emergency.Length; i++)
        {
            for(int j = 0; j < emergency.Length; j++)
            {
                if(emergency[i] <= emergency[j])  /// 제일 큰 것도 배열에 1이 하나 들어가야 되니까 등호까지 넣었다. 
                {
                    answer[i]++;
                }
            }
        }
        return answer;
    }
}

 

// 응급도 숫자가 가장 낮은 게 가장 마지막 순서(가장 큰 수)로 나오게 한다.

 

파이썬

////////

 

def solution(emergency):
    e = sorted(emergency,reverse=True)
    return [e.index(i)+1 for i in emergency]

 

/////

 

def solution(emergency):
    return [sorted(emergency, reverse=True).index(e) + 1 for e in emergency]

 

자바

/////

 

class Solution {
    public int[] solution(int[] emergency) {
        int[] answer = new int[emergency.length];

        for(int i = 0; i < answer.length; i++)
        {
            if(answer[i] != 0)
            {
                continue;
            }
            
            int idx = 1;
            
            for(int j = 0; j < answer.length; j++)
            {
                if(emergency[i] < emergency[j])
                {
                    idx++;
                }
            }
            
            answer[i] = idx;
        }
        return answer;
    }
}

 

 

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

class Solution {
    public int[] solution(int[] e) {
        return Arrays.stream(e).map(i -> Arrays.stream(e).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).indexOf(i) + 1).toArray();
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Diagnostics;

public class Solution {
    public int solution(int[] array, int n) {
        int answer = 0;
        int dif = 100; // 범위가 1~100 자연수고 아무리 커도 99이기 때문에 적당히 100으로 차이를 정의한다.
        Array.Sort(array);
        
        for(int i=0;i<array.Length;i++)
        {
            if(Math.Abs(array[i]-n) < dif)
            {
                dif = Math.Abs(array[i]-n);
                answer = array[i];
            }
        }
        return answer;
    }
}

 

//배열을 sorting을 하지 않으면, 예를 들어서 [2, 7, 3] 5같은 경우에 7을 선택해버리는 문제가 있어서 소팅하고 시작하는 게 답이다.(테스트 5번이 이거인 듯)

 

파이썬

//////////

 

 

def solution(array, n):
    array.sort(key = lambda x : (abs(x-n), x-n))
    answer = array[0]
    return answer

 

자바

/////////

 

import java.util.*;

class Solution {
    public int solution(int[] array, int n) {
        int answer = 0;
        Arrays.sort(array);
        
        for(int i = 1 ; i < array.length ; i++)
        {
            if(Math.abs(n-array[0]) > Math.abs(n-array[i]))
            {
                array[0] = array[i];
            }
        }
        
        answer = array[0];
        return answer;
    }
}

 

 

class Solution {
    public int solution(int[] array, int n) {
        int answer = 0;
        int min = 0;
        
        for(int num : array)
        {
            if(answer == 0)
            {
                answer = num;
                min = Math.abs(num - n);
            }
            else
            {
                if(Math.abs(num - n) < min)
                {
                    answer = num;
                    min = Math.abs(num - n);
                }
                else if( Math.abs(num - n) == min && num < answer){
                    answer = num;
                }
            }
        }
        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int i, int j, int k) {
        int answer = 0;
        int temp = 1;
        
        for(int a=i;a<=j;a++)
        {
            temp = a;
            while(temp > 0)
            {
                if(temp%10 == k) // 마지막 자리가 k이면 answer++
                {
                    answer++;
                }
                temp /= 10;
            }
        }
        
        return answer;
    }
}

 

//

using System;
using System.Linq;

public class Solution {
    public int solution(int i, int j, int k) {
        int answer = Enumerable.Range(i, j - i + 1).Sum(x => x.ToString().Count(o => o.ToString() == k.ToString()));

        return answer;
    }
}

 

 

파이썬

/////

 

def solution(i, j, k):
    answer = 0
    for n in range(i, j + 1):
        answer += str(n).count(str(k))
    return answer

 

/////////

 

from collections import Counter

def solution(i, j, k):
    answer = 0
    for n in range(i,j+1):
        answer += Counter(str(n))[str(k)]
    return answer

 

자바

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

 

class Solution {
    public int solution(int i, int j, int k) {
        String str = "";
        
        for(int a = i; a <= j; a++) 
        {
            str += a+"";
        }

        return str.length() - str.replace(k+"", "").length();
    }
}

 

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

 

class Solution {
    public int solution(int i, int j, int k) {
        int answer = 0;

        for (int num = i; num <= j; num++)
        {
            int tmp = num;
            while (tmp != 0)
            {
                if (tmp % 10 == k)
                    answer++;
                tmp /= 10;
            }
        }
        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int[,] solution(int[] num_list, int n) {
        int[,] answer = new int[num_list.Length / n, n];
        int updown = 0;
        int line = 0;
        
        for(int i=0;i<num_list.Length;i++)
        {
            answer[updown,line] = num_list[i]; 
            line++; // 두 번째 인덱스 다 채우도록 까지 플러스 해준다.
            if(line == n)
            {
                updown++; // 처음 인덱스 증가 시킨다.
                line = 0; // 두 번째 인덱스 초기화
            }
        }
        return answer;
    }
}

 

파이썬

//////

 

def solution(num_list, n):
    answer = []
    for i in range(0, len(num_list), n):
        answer.append(num_list[i:i+n])
    return answer

 

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

 

def solution(num_list, n):
    answer = []

    for i in range(len(num_list)//n) :
        answer.append(num_list[i*n:(i+1)*n])

    return answer

 

자바

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

 

 

class Solution {
    public int[][] solution(int[] num_list, int n) {
        int[][] answer = {};
        int length = num_list.length;
        answer = new int[length/n][n];

        for(int i=0; i<length; i++)
        {
            answer[i/n][i%n]=num_list[i];
        }

        return answer;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public string solution(string letter) {
        string answer = "";
        string[] morse = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
        // Split()은 문자열을 잘라주고 현재 공백을 기준으로 자름
        foreach(string a in letter.Split(" "))
        {
            answer += Convert.ToChar(Array.IndexOf(morse, a) + 97);
        }

 

// IndexOf()는 동일한 문자열이 존재할 경우 문자열의 위치를 반환한다. 문자열의 위치에 97을 더해 Convert.ToChar()로 변환하면 그에 맞는 문자로 변환된다.
        
        return answer;
    }
}

 

 

파이썬

////

 

def solution(letter):
    answer = ''

    morse = { 
        '.-':'a','-...':'b','-.-.':'c','-..':'d','.':'e','..-.':'f',
        '--.':'g','....':'h','..':'i','.---':'j','-.-':'k','.-..':'l',
        '--':'m','-.':'n','---':'o','.--.':'p','--.-':'q','.-.':'r',
        '...':'s','-':'t','..-':'u','...-':'v','.--':'w','-..-':'x',
        '-.--':'y','--..':'z'
    }   

    letter_ls = letter.split()
    for l in letter_ls:
        answer += morse[l]

    return answer

 

//////////

 

def solution(letter):
    answer = ''
    letter = letter.split()
    morse = { 
    '.-':'a','-...':'b','-.-.':'c','-..':'d','.':'e','..-.':'f',
    '--.':'g','....':'h','..':'i','.---':'j','-.-':'k','.-..':'l',
    '--':'m','-.':'n','---':'o','.--.':'p','--.-':'q','.-.':'r',
    '...':'s','-':'t','..-':'u','...-':'v','.--':'w','-..-':'x',
    '-.--':'y','--..':'z'
    }
    for c in letter:
        answer += morse[c]

    return answer

 

자바

/////

 

import java.util.Map;
import java.util.HashMap;

class Solution {
    public String solution(String letter) {
        String answer = "";
        Map<String, String> morse = new HashMap<>(){
            {
                put(".-","a");
                put("-...","b");
                put("-.-.","c");
                put("-..","d");
                put(".","e");
                put("..-.","f");
                put("--.","g");
                put("....","h");
                put("..","i");
                put(".---","j");
                put("-.-","k");
                put(".-..","l");
                put("--","m");
                put("-.","n");
                put("---","o");
                put(".--.","p");
                put("--.-","q");
                put(".-.","r");
                put("...","s");
                put("-","t");
                put("..-","u");
                put("...-","v");
                put(".--","w");
                put("-..-","x");
                put("-.--","y");
                put("--..","z");
            }
        };
        String[] letters = letter.split(" ");
        for(String str : letters){
            answer += morse.get(str);
        }
        return answer;
    }
}

 

/////

 

class Solution {
    public String solution(String letter) {
        String answer = "";
        String[] mos = {".-","-...","-.-.","-..",".","..-.","--.","....","..",
                        ".---","-.-",".-..","--","-.","---",".--.","--.-",".-.",
                        "...","-","..-","...-",".--","-..-","-.--","--.."};
        String[] alpha = {"a","b","c","d","e","f","g","h","i","j","k","l","m",
                          "n","o","p","q","r","s","t","u","v","w","x","y","z"};

        String[] str = letter.split(" ");
        int idx = 0;
        for(int i =0; i<str.length; i++)
        {
            for(int j =0; j<mos.length; j++)
            {
                if(mos[j].equals(str[i]))
                {
                    idx = j;
                    break;
                }
            }
            answer += alpha[idx];
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Linq;

public class Solution {
    public int solution(string before, string after) {
        int answer = 0;
        before = string.Concat(before.OrderBy(x => x));
        after = string.Concat(after.OrderBy(x => x));
        
        answer = after.Contains(before) ? 1 : 0;
        return answer;
    }
}

 

// 소팅한다음에 포함관계인지 확인한다. 이거는 두 문자열의 길이가 똑같아서 가능한 방식.

 

파이썬

/////

def solution(before, after):
    before=sorted(before)
    after=sorted(after)
    if before==after:
        return 1
    else:
        return 0

 

자바

/////

 

import java.util.Arrays;
class Solution {
    public int solution(String before, String after) {
        char[] a = before.toCharArray();
        char[] b = after.toCharArray();
        Arrays.sort(a);
        Arrays.sort(b);

        return new String(a).equals(new String(b)) ? 1 :0;
    }
}

 

 

class Solution {
    public int solution(String before, String after) {
        int answer = 1;

        int[] alphas1 = new int[26];
        int[] alphas2 = new int[26];

        for(int i=0; i<before.length(); i++)
        {
            alphas1[before.charAt(i)-'a']++;
            alphas2[after.charAt(i)-'a']++;
        }

        for(int i=0; i<alphas1.length; i++)
        {
            if(alphas1[i]!=alphas2[i]) answer=0;
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글