-
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
19 changed files
with
464 additions
and
8 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
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
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; | ||
} |
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,35 @@ | ||
#include <iostream> | ||
#include <deque> | ||
#include <vector> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
ios::sync_with_stdio(false); cin.tie(NULL); | ||
int n; | ||
cin >> n; | ||
vector <int> dataStructure(n); //μ€ν μΈμ§ νμΈμ§ μ λ ₯λ°κΈ° | ||
for (auto& i : dataStructure){ | ||
cin >> i; | ||
} | ||
|
||
deque <int> queuestack; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
int x; | ||
cin >> x; | ||
if (dataStructure.at(i) == 0) //νμΈ κ²½μ°μλ§ μ²λ¦¬, μ€νμ 무쑰건 μ λ ₯κ°μ΄ λμ€κΈ°μ μλ€κ³ λ³΄λ©΄λ¨ | ||
queuestack.push_back(x); | ||
} | ||
int m; | ||
cin >> m; | ||
for (int i = 0; i < m; i++) | ||
{ | ||
int x; | ||
cin >> x; | ||
queuestack.push_front(x); | ||
cout << queuestack.back() << " "; | ||
queuestack.pop_back(); | ||
} | ||
return 0; | ||
} |
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,33 @@ | ||
#include <iostream> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); | ||
|
||
priority_queue <int, vector<int>, greater<int>> pq; //μ΅μ νμΌλ‘ μ°μ μμ ν μ μΈ | ||
int n; | ||
cin >> n; | ||
for (int i = 0; i < n; i++) //μ°μ μμ νμ λ€ λ£μ | ||
{ | ||
int x; | ||
cin >> x; | ||
pq.push(x); | ||
} | ||
int result = 0; | ||
while(pq.size() > 1) //μ°μ μμ νμ κ°μ΄ νλλ§ λ¨μ λ κΉμ§ λ°λ³΅ | ||
{ | ||
// μ°μ μμ νμμ κ°μ₯ μμ λ μλ₯Ό κΊΌλ΄μ ν©μΉ¨ | ||
int a = pq.top(); | ||
pq.pop(); | ||
int b = pq.top(); | ||
pq.pop(); | ||
int sum = a + b; | ||
pq.push(sum); // ν©μΉ κ²°κ³Όλ₯Ό μ°μ μμ νμ λ€μ λ£μ | ||
|
||
result += sum; // κ²°κ³Όκ°μ λμ | ||
} | ||
cout << result; | ||
return 0; | ||
} |
Oops, something went wrong.