From 813717f824ddc6b1c96746c7cdb2b295c1c04314 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Wed, 6 May 2026 16:32:07 +0900 Subject: [PATCH] programmers 20260503-06 --- code_study/programmers/숫자 찾기/problem.txt | 13 +++++ code_study/programmers/숫자 찾기/solution.js | 6 ++ code_study/programmers/숫자 찾기/solution.ts | 7 +++ code_study/programmers/옹알이(1)/problem.txt | 17 ++++++ .../programmers/옹알이(1)/solution.swift | 25 +++++++++ code_study/programmers/평행/problem.txt | 17 ++++++ code_study/programmers/평행/solution | Bin 0 -> 34088 bytes code_study/programmers/평행/solution.c | 53 ++++++++++++++++++ 8 files changed, 138 insertions(+) create mode 100644 code_study/programmers/숫자 찾기/problem.txt create mode 100644 code_study/programmers/숫자 찾기/solution.js create mode 100644 code_study/programmers/숫자 찾기/solution.ts create mode 100644 code_study/programmers/옹알이(1)/problem.txt create mode 100644 code_study/programmers/옹알이(1)/solution.swift create mode 100644 code_study/programmers/평행/problem.txt create mode 100755 code_study/programmers/평행/solution create mode 100644 code_study/programmers/평행/solution.c diff --git a/code_study/programmers/숫자 찾기/problem.txt b/code_study/programmers/숫자 찾기/problem.txt new file mode 100644 index 0000000..d0167c9 --- /dev/null +++ b/code_study/programmers/숫자 찾기/problem.txt @@ -0,0 +1,13 @@ +정수 num과 k가 매개변수로 주어질 때, num을 이루는 숫자 중에 k가 있으면 num의 그 숫자가 있는 자리 수를 return하고 +없으면 -1을 return 하도록 solution 함수를 완성해보세요. + +제한사항 +0 < num < 1,000,000 +0 ≤ k < 10 +num에 k가 여러 개 있으면 가장 처음 나타나는 자리를 return 합니다. + +입출력 예 +num k result +29183 1 3 +232443 4 4 +123456 7 -1 diff --git a/code_study/programmers/숫자 찾기/solution.js b/code_study/programmers/숫자 찾기/solution.js new file mode 100644 index 0000000..b6bd4ef --- /dev/null +++ b/code_study/programmers/숫자 찾기/solution.js @@ -0,0 +1,6 @@ +var solution = function (num, k) { + return ("a" + num).indexOf(String(k)); +}; +var num = 123456; +var k = 7; +console.log(solution(num, k)); diff --git a/code_study/programmers/숫자 찾기/solution.ts b/code_study/programmers/숫자 찾기/solution.ts new file mode 100644 index 0000000..f9761e5 --- /dev/null +++ b/code_study/programmers/숫자 찾기/solution.ts @@ -0,0 +1,7 @@ +const solution = (num: number, k: number): number => { + return ("a" + num).indexOf(String(k)); +} + +const num: number = 123456; +const k: number = 7; +console.log(solution(num, k)); \ No newline at end of file diff --git a/code_study/programmers/옹알이(1)/problem.txt b/code_study/programmers/옹알이(1)/problem.txt new file mode 100644 index 0000000..5a423be --- /dev/null +++ b/code_study/programmers/옹알이(1)/problem.txt @@ -0,0 +1,17 @@ +머쓱이는 태어난 지 6개월 된 조카를 돌보고 있습니다. +조카는 아직 "aya", "ye", "woo", "ma" 네 가지 발음을 최대 한 번씩 사용해 조합한(이어 붙인) 발음밖에 하지 못합니다. +문자열 배열 babbling이 매개변수로 주어질 때, +머쓱이의 조카가 발음할 수 있는 단어의 개수를 return하도록 solution 함수를 완성해주세요. + +제한사항 +1 ≤ babbling의 길이 ≤ 100 +1 ≤ babbling[i]의 길이 ≤ 15 + +babbling의 각 문자열에서 "aya", "ye", "woo", "ma"는 각각 최대 한 번씩만 등장합니다. +즉, 각 문자열의 가능한 모든 부분 문자열 중에서 "aya", "ye", "woo", "ma"가 한 번씩만 등장합니다. +문자열은 알파벳 소문자로만 이루어져 있습니다. + +입출력 예 +babbling result +["aya", "yee", "u", "maa", "wyeoo"] 1 +["ayaye", "uuuma", "ye", "yemawoo", "ayaa"] 3 \ No newline at end of file diff --git a/code_study/programmers/옹알이(1)/solution.swift b/code_study/programmers/옹알이(1)/solution.swift new file mode 100644 index 0000000..2cf5cbd --- /dev/null +++ b/code_study/programmers/옹알이(1)/solution.swift @@ -0,0 +1,25 @@ +import Foundation + +func solution(_ babbling:[String]) -> Int { + let possible: [String: Int] = ["aya": 3, "ye": 2, "woo": 3, "ma": 2] + var ans: Int = 0 + + for str in babbling { + var cnt: Int = str.count + + for key in possible.keys { + if str.contains(key) { + cnt -= possible[key, default: 0] + } + } + + if cnt == 0 { + ans += 1 + } + } + + return ans +} + +let babbling: [String] = ["aya", "yee", "u", "maa", "wyeoo"] +print(solution(babbling)) diff --git a/code_study/programmers/평행/problem.txt b/code_study/programmers/평행/problem.txt new file mode 100644 index 0000000..0b9946e --- /dev/null +++ b/code_study/programmers/평행/problem.txt @@ -0,0 +1,17 @@ +점 네 개의 좌표를 담은 이차원 배열 dots가 다음과 같이 매개변수로 주어집니다. +[[x1, y1], [x2, y2], [x3, y3], [x4, y4]] +주어진 네 개의 점을 두 개씩 이었을 때, +두 직선이 평행이 되는 경우가 있으면 1을 없으면 0을 return 하도록 solution 함수를 완성해보세요. + +제한사항 +dots의 길이 = 4 +dots의 원소는 [x, y] 형태이며 x, y는 정수입니다. +0 ≤ x, y ≤ 100 +서로 다른 두개 이상의 점이 겹치는 경우는 없습니다. +두 직선이 겹치는 경우(일치하는 경우)에도 1을 return 해주세요. +임의의 두 점을 이은 직선이 x축 또는 y축과 평행한 경우는 주어지지 않습니다. + +입출력 예 +dots result +[[1, 4], [9, 2], [3, 8], [11, 6]] 1 +[[3, 5], [4, 1], [2, 4], [5, 10]] 0 diff --git a/code_study/programmers/평행/solution b/code_study/programmers/평행/solution new file mode 100755 index 0000000000000000000000000000000000000000..2974d4cb3de0f7901d170f15ca0990a60ece0c92 GIT binary patch literal 34088 zcmeI5du&@*9mmg&^Kf2G(u8$uy2NE|m$X}4ty`NvCUm(3YBIpM%ah`Z2sp()CN zosYI1ZacW2tSd!LUTL~XqdFfVP*FPCIy+Xn)qHuSP3U?7%toUKMTvS(L}{dnwcaG= zPW6V-laNl&wIul>zBI-_Q6kY;S7ga#ttS_2^&ZwENH^EB>-E4;6-9A}f|2D3TI-$C z>uuHJNjKNi%}X8XMWSI}ut&F8>rLqOigZ8eX0g^*lvwadU(loYg54nmTI-$H>vify zNVnE7*Qa%TU9Ho)vty^yvVY$pZFOaRQ=wPI(%WF9Mr&1xrYJq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vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k z025#WOn?b60Vco%m;e)C0!)AjFoDmUfCCi|p!K5B+2q=P0bl?z9}G)pe;cBXWkkz{ zMaz@$2Lcif{g(Ekb)uoDbOJGoqC}!Dcc0?!?Nhp4KL1KfPs|ne2&Fsh^$I26^7}(> z^xlBGe?TbxVP7!Xt=&jc#2OmW9~Icd=qg+$an7wx3G^!76JB>L>Q#EZE{``XiUTfR zP?SeP{#eu(3X0W8nJoTDeI$BDkLf{uq@x)!fq_~73G{A|IsDfJ3RM|3A)n6Mr80C5 z?*@}jwhd?=?GF{yn0*#M<laGgLvZ-w*( zogGdi_x|Pww?EY7Y6{WAn`Gf~*#)e`D=-;rQv(~8S9(_DVYB6_JD+gl)1?Y_e`45? zha;W;C&?ey!z5!a_;9wq{nKshf3?2oqf4)T=?{lgf7<)`7uzn^_~z!a9shc? z;jx$h^!)K3U;gKtzyJ6jFI7MO{rOK@|G(u&fBW8{_rrT${M!${{6S(<^3wUA%^d%^ RtMzPt;aRz_pzs2K{Rab#f9wDN literal 0 HcmV?d00001 diff --git a/code_study/programmers/평행/solution.c b/code_study/programmers/평행/solution.c new file mode 100644 index 0000000..0024891 --- /dev/null +++ b/code_study/programmers/평행/solution.c @@ -0,0 +1,53 @@ +#include +#include +#include + +int solution(int** dots, size_t dots_rows, size_t dots_cols) { + int pair[3][4] = {{0, 1, 2, 3}, {0, 2, 1, 3}, {0, 3, 1, 2}}; + + for(int i=0; i<3; i++) { + double x1 = (double)dots[pair[i][0]][0], y1 = (double)dots[pair[i][0]][1]; + double x2 = (double)dots[pair[i][1]][0], y2 = (double)dots[pair[i][1]][1]; + double x3 = (double)dots[pair[i][2]][0], y3 = (double)dots[pair[i][2]][1]; + double x4 = (double)dots[pair[i][3]][0], y4 = (double)dots[pair[i][3]][1]; + + double grad1 = (x2 - x1) / (y2 - y1); + double grad2 = (x4 - x3) / (y4 - y3); + + if(grad1 == grad2) return 1; + } + + return 0; +} + +int main() { + + int** dots1 = (int**)malloc(sizeof(int*) * 4); + int** dots2 = (int**)malloc(sizeof(int*) * 4); + + for(int i=0; i<4; i++) { + dots1[i] = (int*)malloc(sizeof(int) * 2); + dots2[i] = (int*)malloc(sizeof(int) * 2); + } + + dots1[0][0] = 1; dots1[0][1] = 4; + dots1[1][0] = 9; dots1[1][1] = 2; + dots1[2][0] = 3; dots1[2][1] = 8; + dots1[3][0] = 11; dots1[3][1] = 6; + + dots2[0][0] = 3; dots2[0][1] = 5; + dots2[1][0] = 4; dots2[1][1] = 1; + dots2[2][0] = 2; dots2[2][1] = 4; + dots2[3][0] = 5; dots2[3][1] = 0; + + printf("%d %d\n",solution(dots1, 4, 2) ,solution(dots2, 4, 2)); + + for(int i=0; i<4; i++) { + free(dots1[i]); + free(dots2[i]); + } + + free(dots1); free(dots2); + + return 0; +} \ No newline at end of file