본문 바로가기
공부,일/코딩테스트

카카오톡 신입 공채

by fromnothing1 2021. 8. 20.

https://tech.kakao.com/2017/09/27/kakao-blind-recruitment-round-1/

 

카카오 신입 공채 1차 코딩 테스트 문제 해설

‘블라인드’ 전형으로 실시되어 시작부터 엄청난 화제를 몰고 온 카카오 개발 신입 공채. 그 첫 번째 관문인 1차 코딩 테스트가 지난 9월 16일(토) 오후 2시부터 7시까지 장장 5시간 동안 온라인

tech.kakao.com

 

1. 지도그리기

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            const int n = 5;
            int[] arr1 = new int[n] { 9, 20, 28, 18, 11 };
            int[] arr2 = new int[n] { 30, 1, 21, 17, 28 };
            int[] arr3 = new int[n];
            char[][] arr4 = new char[n][];
            string[] result = new string[n];

            // 0 으로 초기화 
            for (int i = 0; i < n; i++)
            {
                arr4[i] = new char[n];
                for (int j = 0; j < n; j++)
                {
                    arr4[i][j] = ' ';
                }
            }
            for (int i = 0; i < n; i++)
            {
                arr3[i] = arr1[i] | arr2[i];
            }
            int temp;
            for (int i = 0; i < n; i++)
            {
                temp = arr3[i];
                int count = 1;
                int remmender = 0;
                while (temp != 0)
                {
                    remmender = temp % 2;
                    if (remmender == 1)
                    {
                        arr4[i][n - count] = '#';
                    }
                    temp = temp / 2;
                    count++;
                }
            }

            for (int i = 0; i < n; i++)
            {
                result[i] = new string(arr4[i]);
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write(result[i][j]);
                }
                Console.WriteLine("");
            }

        }
    }
}

 

2번문제 

다트 점수 계산하기

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = "1S2D*3T";
            string b = "1T2D3D#";
            string c = "1S*2T*3S";
            string d = "1D2S0T";



            Console.WriteLine(CalPoint(a));
            Console.WriteLine(CalPoint(b));
            Console.WriteLine(CalPoint(c));
            Console.WriteLine(CalPoint(d));

        }

        static int CalPoint(string str)
        {
            int result = 0;
            int[] num = new int[3];
            int count = 0;
            string[] arr = new string[3];

            count = 0;
            for (int i = 0; i < str.Length; i++)
            {
                if (47 < str[i] && str[i] < 58)
                {
                    num[count] = i;
                    count++;
                }
            }

            arr[0] = str.Substring(num[0], num[1]);
            arr[1] = str.Substring(num[1], num[2] - num[1]);
            arr[2] = str.Substring(num[2], str.Length - num[2]);

            int a =(int)Math.Pow(num[1], 2);

            num = new int[3] { 0, 0, 0 };

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                {
                    if (47 < arr[i][j] && arr[i][j] < 58) // 숫자인경우 
                    {

                        num[i] += (arr[i][j] - 48);

                    }
                    else if(arr[i][j] == 'D')
                    {
                        num[i] = (int)Math.Pow(num[i], 2);
                    }
                    else if (arr[i][j] == 'T')
                    {
                        num[i] = (int)Math.Pow(num[i], 3);
                    }
                    else if (arr[i][j] == '*')
                    {
                        num[i] = num[i]*2;
                        if (i > 0)
                        {
                            num[i - 1] = num[i - 1] * 2;
                        }
                    }
                    else if (arr[i][j] == '#')
                    {
                        num[i] = num[i] * -1;
                    }

                }

            }

            for (int i = 0; i < 3; i++)
            {
                result += num[i];
            }


            return result;
        }


    }
}

 

3 번문제 

캐쉬 구하깅

using System;
using System.Collections.Generic;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> cash = new List<string>();
            int cash_size = 3;
            int runtime = 0;
            string[] array = {"Jeju", "Pangyo", "Seoul",
                "NewYork", "LA", "Jeju","Pangyo", "Seoul", "NewYork", "LA"};
            string[] array1 = {"Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul"};
            array = array1;
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = array[i].ToLower();
            }
            for (int i = 0; i < cash_size; i++)
            {
                cash.Add(array[i]);
                runtime += 5;
            }

            for (int i = cash_size; i < array.Length; i++)
            {
                int Index = cash.FindIndex(a => a.Contains(array[i]));
                if (Index == -1 )
                {
                    try
                    {
                        cash.RemoveAt(0);
                        cash.Add(array[i]);
                    }
                    catch (Exception)
                    {
                    }
                    runtime += 5;
                }
                else
                {
                    cash.RemoveAt(Index);
                    cash.Add(array[i]);
                    runtime += 1;
                }
            }
            Console.WriteLine(runtime);
        }

    }
}

 

4. 셔틀버스(난이도: 중)

이게 제일 어려운거 같은데 ;;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            const int array_num = 16;
            string[] input = new string[array_num] { "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59" };

            int Max_bus_number = 10;
            int time = 60;
            int max = 45;


            //{"09:10", "09:09", "08:00"}	
            //{"09:00", "09:00", "09:00", "09:00"}  
            //{"00:01", "00:01", "00:01", "00:01", "00:01"}   
            //{"23:59"}  
            //{"23:59","23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59"}


            List<int> input_int = new List<int>();

            for (int i = 0; i < array_num; i++)
            {
                input_int.Add(int.Parse(input[i].Substring(0, 2)) * 60 + int.Parse(input[i].Substring(3, 2)));
            }

            input_int.Sort();

            int[] bus_time = new int[Max_bus_number];
            for (int i = 0; i < Max_bus_number; i++)
            {
                bus_time[i] = 9 * 60 + i * time;
            }


            int person_Num = 0;
            int LastPerson = 0;
            bool bus_is_full = false;

            for (int i = 0; i < Max_bus_number; i++)
            {
                for (int j = 0; j < max; j++)
                {
                    if (person_Num > array_num-1)
                    {
                        break;
                    }
                    if (input_int[person_Num] <= bus_time[i])
                    {
                        if (Max_bus_number-1 == i)
                        {
                            LastPerson = input_int[person_Num];
                            if (j == max-1)
                            {
                                bus_is_full = true;
                            }
                        }
                        person_Num++;
                    }
                    else
                    {
                        break;
                    }

                }
            }
            int result;
            if (LastPerson == 0)
            {
                result = bus_time[Max_bus_number-1];
            }
            else
            {
                if (bus_is_full)
                {
                    result = LastPerson - 1;
                }
                else
                {
                    result = bus_time[Max_bus_number-1];
                }
            }

            string result1 = string.Format("{0,2:00}:{1,2:00}", (result / 60),(result % 60));
            Console.WriteLine(result1);
        }
    }
}

5. 뉴스 클러스터링(난이도: 중)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static List<string> Make_string_List(string str)
        {
            str = str.ToLower();
            List<string> temp =  new List<string>();
            for (int i = 0; i < str.Length - 1; i++)
            {
                if (str[i] <= 'z' && str[i] >= 'a')
                {
                    if (str[i + 1] <= 'z' && str[i + 1] >= 'a')
                    {
                        temp.Add(str.Substring(i, 2));
                    }
                }
            }
            return temp;

        }
        static void Main(string[] args)
        {
            //string input = "E=M*C^2";
            //string input1 = "french";
            //string input2 = "FRANCE";
            //string input1 = "aa1+aa2";
            //string input2 = "AAAA12";

            string input1 = "handshake";
            string input2 = "shake hands";

            List<string> string1;
            List<string> string2;


            string1 = Make_string_List(input1);
            string2 = Make_string_List(input2);

            Dictionary<string, int> DicString1 = new Dictionary<string, int>();
            Dictionary<string, int> DicString2 = new Dictionary<string, int>();

            foreach (string item in string1)
            {
                try
                {
                    DicString1.Add(item, 1);
                }
                catch (Exception)
                {
                    DicString1[item]++;
                }
            }
            foreach (string item in string2)
            {
                try
                {
                    DicString2.Add(item, 1);
                }
                catch (Exception)
                {
                    DicString2[item]++;
                }
            }
            int sum = 0 ;
            int cros = 0 ;

            foreach (var item in DicString1)
            {
                if (DicString2.ContainsKey(item.Key))
                {
                    cros += Math.Min(DicString1[item.Key], item.Value);
                }
            }
            //------------------------sum---------------------------
            foreach (var item in DicString1)
            {
                if (DicString2.ContainsKey(item.Key))
                {
                    sum += Math.Max(DicString2[item.Key], item.Value);
                    DicString2.Remove(item.Key);
                }
                else
                {
                    sum += item.Value;
                }
            }
            foreach (var item in DicString2)
            {
                sum += item.Value;
            }
            double result = ((double)cros / sum) * 65536;
            result = Math.Truncate(result);

            Console.WriteLine(result);
        }
    }
}

 

6. 프렌즈 4블록

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {

            //string[] input = new string[] { "CCBDE", "AAADE", "AAABF", "CCBBF" };
            string[] input = new string[] { "TTTANT",
                                                "RRFACC",
                                                "RRRFCC",
                                                "TRRRAA",
                                                "TTMMMF",
                                                "TMMTTJ"};

            int height = 6;
            int width = 6;

            char[][] Copy_input = new char[input.Length][];
            for (int i = 0; i < input.Length; i++)
            {
                Copy_input[i] = input[i].ToCharArray();
            }

            bool onemoretiem = true;

            Dictionary<int, List<int>> hitBox = new Dictionary<int, List<int>>();
            while (onemoretiem)
            {
                onemoretiem = false;
                for (int i = 0; i < height - 1; i++)
                {
                    for (int j = 0; j < width - 1; j++)
                    {
                        if (Copy_input[i][j] == ' ')
                        {
                            continue;
                        }
                        if (Copy_input[i][j] == Copy_input[i + 1][j]
                            && Copy_input[i][j] == Copy_input[i][j + 1]
                            && Copy_input[i][j] == Copy_input[i + 1][j + 1])
                        {
                            onemoretiem = true;
                            if (hitBox.ContainsKey(j))
                            {
                                hitBox[j].Add(i);
                                hitBox[j].Add(i + 1);
                            }
                            else
                            {
                                hitBox.Add(j, new List<int>());
                                hitBox[j].Add(i);
                                hitBox[j].Add(i + 1);
                            }
                            if (hitBox.ContainsKey(j + 1))
                            {
                                hitBox[j + 1].Add(i);
                                hitBox[j + 1].Add(i + 1);
                            }
                            else
                            {
                                hitBox.Add(j + 1, new List<int>());
                                hitBox[j + 1].Add(i);
                                hitBox[j + 1].Add(i + 1);
                            }
                        }
                    }
                }
                int count;
                foreach (var item in hitBox)
                {
                    count = height - 1;
                    for (int i = height - 1; i > -1; i--)
                    {
                        if (item.Value.Contains(i))
                        {
                            continue;
                        }
                        else
                        {
                            Copy_input[count][item.Key] = Copy_input[i][item.Key];
                            count--;
                        }
                    }
                    try // count = -1 일 경우 아무 것도 안함 
                    {
                        for (int j = count; j > -1; --j)
                        {
                            Copy_input[j][item.Key] = ' ';
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                hitBox = new Dictionary<int, List<int>>(); // hitbox clear;
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        Console.Write(Copy_input[i][j]);
                    }
                    Console.WriteLine("");
                }
                Console.WriteLine("-----------------------");
            }

            int result = 0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (Copy_input[i][j] == ' ')
                    {
                        result++;
                    }
                }

            }

            Console.WriteLine("지워진 칸의 숫자 : " + result);




            
        }
    }
}

7. 추석 트래픽(난이도: 상)

 

 

'공부,일 > 코딩테스트' 카테고리의 다른 글

탐욕법  (0) 2021.11.04
전화번호 목록  (0) 2021.10.24
tow sum  (0) 2021.10.24
코딩 테스트 사이트 모음  (0) 2021.10.18
1 만들기(Dynamic Programming )  (0) 2021.10.17

댓글