programmers 20260503-06

This commit is contained in:
songyc macbook 2026-05-06 16:32:07 +09:00
parent bfa71e91d8
commit 813717f824
8 changed files with 138 additions and 0 deletions

View File

@ -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

View File

@ -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));

View File

@ -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));

View File

@ -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

View File

@ -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))

View File

@ -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

Binary file not shown.

View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
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;
}