-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
827 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function solution(polynomial) { | ||
const values = polynomial.split(' + '); | ||
console.log("values : ", values); | ||
let x = 0; | ||
let c = 0; | ||
for(let i=0;i<values.length;i++) { | ||
const item = values[i]; | ||
if(item[item.length-1] !== 'x') { | ||
c += Number(item); | ||
} | ||
else { | ||
// x์ผ๋ | ||
const num = item.split('x')[0]; | ||
if(num === '') { | ||
x += 1; | ||
} else { | ||
x += Number(num) | ||
} | ||
} | ||
} | ||
let answer = ''; | ||
if(x === 1) { | ||
answer += 'x'; | ||
} | ||
if(x > 1) { | ||
answer += `${x}x`; | ||
} | ||
|
||
if(x === 0 && c > 0) { | ||
answer += c; | ||
} | ||
else if(c > 0) { | ||
answer += ` + ${c}`; | ||
} | ||
return answer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function solution(numbers) { | ||
var answer = []; | ||
|
||
|
||
let cnt = 0; | ||
while(cnt < numbers.length){ | ||
answer.push(numbers[cnt]*2); | ||
cnt = cnt +1; | ||
} | ||
return answer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function solution(numer1, denom1, numer2, denom2) { | ||
var answer = []; | ||
const numer = numer1 * denom2 + numer2 * denom1; | ||
const denom = denom1 * denom2; | ||
|
||
let minNumber; | ||
if(numer < denom){ | ||
minNumber = numer; | ||
} else { | ||
minNumber = denom; | ||
} | ||
|
||
|
||
while(true){ | ||
if(numer % minNumber === 0){ | ||
if(denom % minNumber === 0){ | ||
return [numer / minNumber, denom / minNumber]; | ||
} | ||
} | ||
minNumber = minNumber -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function solution(array) { | ||
|
||
let arrayCnt = 0; | ||
let newArray = []; | ||
while(arrayCnt < array.length){ | ||
let minNumber = 1000; | ||
|
||
let cnt = 0; | ||
while(cnt < array.length){ | ||
if(minNumber > array[cnt]){ | ||
minNumber = array[cnt]; | ||
} | ||
cnt = cnt + 1; | ||
} | ||
|
||
newArray.push(minNumber); | ||
|
||
let cnt2 = 0; | ||
while(cnt2 < array.length){ | ||
if(minNumber === array[cnt2]){ | ||
array[cnt] = 1000; | ||
break; | ||
} | ||
cnt2 = cnt2 + 1 | ||
} | ||
|
||
arrayCnt = arrayCnt + 1; | ||
} | ||
return newArray[Math.floor(array.length / 2)]; | ||
} |
27 changes: 27 additions & 0 deletions
27
honggukang0623/์ง๊ฐ์ผ๊ฐํ ์ถ๋ ฅํ๊ธฐ/์ง๊ฐ์ผ๊ฐํ ์ถ๋ ฅํ๊ธฐ.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const readline = require('readline'); | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
|
||
let input = []; | ||
|
||
rl.on('line', function (line) { | ||
input = line.split(' '); | ||
}).on('close', function () { | ||
const n = Number(input[0]); | ||
|
||
let line = 1; | ||
while(line <= n){ | ||
|
||
let starStr = ""; | ||
let cnt = 0; | ||
while(cnt < line){ | ||
starStr = starStr+"*" | ||
cnt = cnt + 1; | ||
} | ||
|
||
console.log(starStr) | ||
line = line + 1; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const fs = require('fs'); | ||
const filepath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; | ||
const input = fs.readFileSync(filepath).toString().trim().split('\n'); | ||
//์ ๋ ฅ ๋ฐ์ดํฐ ์ ๋ฆฌ | ||
const N = +input.shift(); | ||
const students = input.map(x => { | ||
const [num, ...likes] = x.trim().split(' ').map(Number); | ||
return { num, likes }; | ||
}); | ||
|
||
let board = Array.from({ length: N }, () => Array(N).fill(0)); | ||
|
||
const dr = [-1, 1, 0, 0]; | ||
const dc = [0, 0, -1, 1]; | ||
|
||
main(); | ||
|
||
function main(){ | ||
for(let i=0; i< N**2; i++){ | ||
if(i == 0){ | ||
board[1][1] = students[i].num; //์ฒซํ์์ 1,1์ ๋ฌด์กฐ๊ฑด ์๋๋ค. | ||
continue; | ||
} | ||
choiceSeat(students[i].num); //ํ์์ ์กฐ๊ฑด์ ๋ง๊ฒ ์ํ๊ธฐ | ||
} | ||
console.log(calcSatisfy()); //๋ชจ๋ ์์ ํ ๋ง์กฑ๋ ๊ณ์ฐํ๊ธฐ | ||
} | ||
|
||
// ์ต์ ์ ์๋ฆฌ ์ ํ ๋ฐ ํ์ ๋ฐฐ์น ํจ์ | ||
function choiceSeat(studentNum){ | ||
const neighborInfos = []; //์ธ์ ์๋ฆฌ ์ ๋ณด๋ฅผ ๋ชจ์ผ๋ ๋ฐฐ์ด | ||
for(let i = 0; i<N; i++){ | ||
for(let j =0; j<N; j++){ | ||
if(board[i][j] !== 0) continue; //์ด๋ฏธ ์ฐจ์๋ ์๋ฆฌ ํจ์ค | ||
neighborInfos.push(getSeatInfo(i, j, studentNum)); | ||
} | ||
} | ||
neighborInfos.sort((a, b) => { | ||
if (a.match !== b.match) { | ||
return b.match - a.match; // match ๊ธฐ์ค ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ | ||
} else if (a.empty !== b.empty) { | ||
return b.empty - a.empty; // empty ๊ธฐ์ค ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ | ||
} else if (a.r !== b.r) { | ||
return a.r - b.r; // r ๊ธฐ์ค ์ค๋ฆ์ฐจ์ ์ ๋ ฌ | ||
} else { | ||
return a.c - b.c; // c ๊ธฐ์ค ์ค๋ฆ์ฐจ์ ์ ๋ ฌ | ||
} | ||
}); | ||
board[neighborInfos[0].r][neighborInfos[0].c] = studentNum; //์ต์ ์ ์์น์ ์ํ๊ธฐ | ||
} | ||
|
||
// ํน์ ์๋ฆฌ์ ์ธ์ ์ ๋ณด ๊ณ์ฐ ํจ์ | ||
function getSeatInfo(r, c, studentNum){ | ||
let empty = 0; | ||
let match = 0; | ||
// ํ์ ๋ฒํธ์ ๋ง๋ ์ข์ํ๋ ํ์๋ค ์ฐพ๊ธฐ | ||
let studentLikes = students.find(student => student.num === studentNum)?.likes || []; | ||
for(let i = 0; i< 4; i++){ | ||
nr = r + dr[i]; | ||
nc= c + dc[i]; | ||
if(nr < 0 || nc < 0 || nr >= N || nc >= N) continue; | ||
if (board[nr][nc] == 0) empty++; | ||
else if(studentLikes.includes(board[nr][nc])) match++ | ||
} | ||
return { r: r, c: c, empty: empty, match: match }; | ||
} | ||
|
||
//๋ง์กฑ๋ ์ฒ๋ฆฌ | ||
function calcSatisfy(){ | ||
let result = 0; | ||
for(let i = 0; i<N; i++){ //๋จ์์๋ ๋ชจ๋ ์๋ฆฌ์ ์ ๋ณด๋ฅผ ์์ง | ||
for(let j =0; j<N; j++){ | ||
result += Math.floor(10 ** (getSeatInfo(i, j ,board[i][j]).match-1)); | ||
} | ||
} | ||
return result; | ||
} | ||
์ถ์ฒ: https://oesnuj.tistory.com/entry/Nodejs-๋ฐฑ์ค-Javascript-21608-์์ด-์ด๋ฑํ๊ต [๋นํธ๋ก ๊ทธ๋ฆฌ๋ ์ฑ์ฅ์ผ๊ธฐ:ํฐ์คํ ๋ฆฌ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
const int BINGO_SIZE = 5; | ||
int board[BINGO_SIZE][BINGO_SIZE]; | ||
|
||
void changeBingo(int target); | ||
int checkBingo(); | ||
|
||
|
||
|
||
int main() | ||
{ | ||
ios::sync_with_stdio(0); cin.tie(0); | ||
for (int i = 0; i < BINGO_SIZE; i++) | ||
{ | ||
for (int j = 0; j < BINGO_SIZE; j++) | ||
{ | ||
cin >> board[i][j]; | ||
} | ||
} | ||
|
||
int sayCnt = 0; | ||
for (int i = 0; i < BINGO_SIZE * BINGO_SIZE; i++) | ||
{ | ||
int num; | ||
cin >> num; | ||
sayCnt++; | ||
changeBingo(num); | ||
if (checkBingo() >= 3) { | ||
cout << sayCnt; | ||
return 0; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
void changeBingo(int target) //์ฌํ์๊ฐ ๋ถ๋ฅธ ์ ์ฒดํฌํ๊ธฐ | ||
{ | ||
for (int i = 0; i < BINGO_SIZE; i++){ | ||
for (int j = 0; j < BINGO_SIZE; j++){ | ||
if (board[i][j] == target){ | ||
board[i][j] = 0; | ||
return; | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
|
||
int checkBingo() //ํ์ฌ ๋ณด๋ํ์ ๋น๊ณ ๊ฐ ๋ช์ค์ธ์ง | ||
{ | ||
int bingoCnt = 0; | ||
|
||
for (int i = 0; i < BINGO_SIZE; i++) //๊ฐ๋ก, ์ธ๋ก ๋น๊ณ ํ์ธ | ||
{ | ||
int horizontal = 0, vertical = 0; | ||
for (int j = 0; j < BINGO_SIZE; j++){ | ||
if (!board[i][j]) | ||
horizontal++; | ||
if (!board[j][i]) | ||
vertical++; | ||
} | ||
if (horizontal == BINGO_SIZE) bingoCnt++; | ||
if (vertical == BINGO_SIZE) bingoCnt++; | ||
} | ||
|
||
int right_diagonal = 0, left_diagonal = 0; | ||
for (int i = 0; i < BINGO_SIZE; i++) //๋๊ฐ์ 2๊ฐ ๋น๊ณ ํ์ธ | ||
{ | ||
if (!board[i][i]) right_diagonal++; | ||
if (!board[i][BINGO_SIZE - i - 1]) left_diagonal++; | ||
} | ||
if (right_diagonal == BINGO_SIZE) bingoCnt++; | ||
if (left_diagonal == BINGO_SIZE) bingoCnt++; | ||
|
||
return bingoCnt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
#include <vector> | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
struct Point | ||
{ | ||
int x, y; | ||
}; | ||
|
||
int calcDistance(Point a, Point b) | ||
{ | ||
return pow(a.x - b.x, 2) + pow(a.y - b.y, 2); | ||
} | ||
|
||
bool compareInfo(Point &a, Point &b) | ||
{ | ||
if(a.x == b.x) | ||
return a.y < b.y; | ||
return a.x < b.x; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int n; | ||
cin >> n; | ||
|
||
while (n--) | ||
{ | ||
vector <Point> v(4); | ||
for (int i = 0; i < 4; i++) { | ||
cin >> v[i].x >> v[i].y; | ||
} | ||
sort(v.begin(), v.end(),compareInfo); | ||
//2 3 | ||
//0 1 | ||
int s1 = calcDistance(v[0], v[1]); //์ ๋ถ | ||
int s2 = calcDistance(v[0], v[2]); | ||
int s3 = calcDistance(v[1], v[3]); | ||
int s4 = calcDistance(v[2], v[3]); | ||
|
||
int dia1 = calcDistance(v[0], v[3]); //๋๊ฐ์ | ||
int dia2 = calcDistance(v[1], v[2]); | ||
if (s1 == s2 && s2 == s3 && s3 == s4 && dia1 == dia2) //๋ค๋ณ์ ๊ธธ์ด๊ฐ ๊ฐ๊ณ ๋๊ฐ์ ์ ๊ธธ์ด๊ฐ ๊ฐ๋ค. | ||
cout << 1 << '\n'; | ||
else | ||
cout << 0 << '\n'; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.