From 85f610f2ce29ae0f588fc20e2b875fd5a5700c48 Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Mon, 27 May 2019 16:15:24 +0900 Subject: [PATCH 01/14] [honux] programmers h-index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 난이도 3점 문제가 좀 이상하다. 분류는 정렬 --- 190524/honux/h-index.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 190524/honux/h-index.js diff --git a/190524/honux/h-index.js b/190524/honux/h-index.js new file mode 100644 index 0000000..e3a5572 --- /dev/null +++ b/190524/honux/h-index.js @@ -0,0 +1,6 @@ +function solution(citations) { + citations.sort((a,b) => (b - a)); + let i = 0; + while (i + 1 <= citations[i]) i++; + return i; +} From 891a6c22a3ffe79a0047886f2bd80787c05676c7 Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Thu, 30 May 2019 10:27:53 +0900 Subject: [PATCH 02/14] Add 190530 problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BOJ 달팽이 --- 190530/problem.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 190530/problem.md diff --git a/190530/problem.md b/190530/problem.md new file mode 100644 index 0000000..35d7125 --- /dev/null +++ b/190530/problem.md @@ -0,0 +1,7 @@ +# 190530 + +## BOJ 1913 달팽이 + +- https://www.acmicpc.net/problem/1913 +- 난이도 2점 + From 0ee56d35669ab6d53407c387582b08dd17e0f890 Mon Sep 17 00:00:00 2001 From: Kong Son Park Date: Mon, 3 Jun 2019 15:40:55 +0900 Subject: [PATCH 03/14] =?UTF-8?q?[=EC=86=8C=EB=8B=88]=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EB=9E=98=EB=A8=B8=EC=8A=A4=20=EB=AA=A8=EC=9D=98?= =?UTF-8?q?=EA=B3=A0=EC=82=AC=20=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98=20?= =?UTF-8?q?=ED=92=80=EC=9D=B4=20(#45)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 190524 H_index 알고리즘 풀이 * 프로그래머스 알고리즘 모의고사 문제풀이 From 078262089b84fe1c6575c0bc5d2841f2c6012013 Mon Sep 17 00:00:00 2001 From: Minjae Lee <0201.mj.lee@gmail.com> Date: Mon, 3 Jun 2019 15:41:12 +0900 Subject: [PATCH 04/14] =?UTF-8?q?Wangmin=20190530=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=ED=92=80=EC=9D=B4=20(#57)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Wangmin] 190523 알고리즘 가장 큰 수 풀이 * [wangmin] programmers 42747 H-index -sort * [wangmin] programmers 42840 모의고사 * [wangmin] baek joon 1913 달팽이 --- 190523/wangmin/pg42746.cpp | 28 ++++++++++++++++++++ 190524/wangmin/pg42747.cpp | 21 +++++++++++++++ 190527/wangmin/pg42840.cpp | 49 +++++++++++++++++++++++++++++++++++ 190530/wangmin/bj1913.cpp | 53 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 190523/wangmin/pg42746.cpp create mode 100644 190524/wangmin/pg42747.cpp create mode 100644 190527/wangmin/pg42840.cpp create mode 100644 190530/wangmin/bj1913.cpp diff --git a/190523/wangmin/pg42746.cpp b/190523/wangmin/pg42746.cpp new file mode 100644 index 0000000..2fbd7a5 --- /dev/null +++ b/190523/wangmin/pg42746.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +using namespace std; + +bool func(string a, string b){ + return a+b > b+a ? true : false; +} + +string solution(vector numbers) { + string answer = ""; + vector str; + for(int i = 0 ; i < numbers.size(); i++){ + str.push_back(to_string(numbers[i])); + } + + sort(str.begin(), str.end(), func); + for(int i = 0; i < str.size(); i++){ + answer += str[i]; + } + if(answer[0] == '0'){ + return "0"; + } + + return answer; +} \ No newline at end of file diff --git a/190524/wangmin/pg42747.cpp b/190524/wangmin/pg42747.cpp new file mode 100644 index 0000000..8d1425a --- /dev/null +++ b/190524/wangmin/pg42747.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +using namespace std; + +int solution(vector citations) { + int h; + sort(citations.begin(),citations.end()); + for(int i = 0; i< citations.size(); i++){ + h = citations.size()-i; + + if(citations[i] >= h){ + return h; + } + + } + return 0; +} + diff --git a/190527/wangmin/pg42840.cpp b/190527/wangmin/pg42840.cpp new file mode 100644 index 0000000..941df3c --- /dev/null +++ b/190527/wangmin/pg42840.cpp @@ -0,0 +1,49 @@ +#include +#include +#include + +using namespace std; + +vector solution(vector answers) { + vector one = {1,2,3,4,5}; + vector two = {2,1,2,3,2,4,2,5}; + vector three = {3,3,1,1,2,2,4,4,5,5}; + + int oneCount = 0; + int twoCount = 0; + int threeCount = 0; + + for(int i = 0; i < answers.size(); i++){ + if(answers[i] == one[i%one.size()]){ + oneCount++; + } + } + + int max = oneCount; + + for(int i = 0; i < answers.size(); i++){ + if(answers[i] == two[i%two.size()]){ + twoCount++; + } + } + + max = (twoCount > max) ? twoCount : max; + + for(int i = 0; i < answers.size(); i++){ + if(answers[i] == three[i%three.size()]){ + threeCount++; + } + } + + max = (threeCount > max) ? threeCount : max; + + + + vector answer; + if(max == oneCount) answer.push_back(1); + if(max == twoCount) answer.push_back(2); + if(max == threeCount) answer.push_back(3); + + + return answer; +} \ No newline at end of file diff --git a/190530/wangmin/bj1913.cpp b/190530/wangmin/bj1913.cpp new file mode 100644 index 0000000..af70292 --- /dev/null +++ b/190530/wangmin/bj1913.cpp @@ -0,0 +1,53 @@ +//https://www.acmicpc.net/problem/1913 + +#include +#include + +using namespace std; + +int main () { + int n,a; + cin >> n >> a; + + vector> vec = vector>(n,(vector(n,0))); + + vector start ={n/2,n/2}; + vector> right = {{-1,0},{0,1},{1,0},{0,-1}}; + vector head = {-1,0}; + + vector aindex = {0,0}; + + // vec[start[0]][start[1]] = 1; + int rightindex = 0; + for(int i = 1; i <= n*n; i ++){ + // vec[start[0],start[1]] + vec[start[0]][start[1]] = i; + + if(i == a){ + aindex = {start[0],start[1]}; + } + + if(vec[start[0]+right[rightindex%4][0]][start[1]+right[rightindex%4][1]] == 0){ + head = right[rightindex%4]; + start[0] = start[0]+head[0]; + start[1] = start[1]+head[1]; + rightindex++; + }else{ + start[0] = start[0]+head[0]; + start[1] = start[1]+head[1]; + } + } + + for(int i = 0; i < n; i++){ + for(int j = 0; j < n; j++){ + cout << vec[i][j]<<" "; + } + cout << "\n"; + } + + cout << aindex[0]+1 << " " << aindex[1]+1< Date: Mon, 3 Jun 2019 15:41:37 +0900 Subject: [PATCH 05/14] Su (#46) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add 190521 problem 프로그래머스 k번째수 * k번째 수 * h번째 인덱스 * mockExam algorithm --- 190527/mockExam.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 190527/mockExam.js diff --git a/190527/mockExam.js b/190527/mockExam.js new file mode 100644 index 0000000..9f3ea56 --- /dev/null +++ b/190527/mockExam.js @@ -0,0 +1,21 @@ +function solution(answers) { + let answer = []; + let supo1 = [1,2,3,4,5]; + let supo2 = [2,1,2,3,2,4,2,5]; + let supo3 = [3,3,1,1,2,2,4,4,5,5]; + let ans1 = howManyCorrect(answers , supo1); + let ans2 = howManyCorrect(answers , supo2); + let ans3 = howManyCorrect(answers , supo3); + let max = Math.max(ans1,ans2,ans3); + if( max === ans1) answer.push(1); + if( max === ans2) answer.push(2); + if( max === ans3) answer.push(3); + + return answer; +} + +function howManyCorrect(ans , supo) { + return ans.filter(function(v, i){ + return v === supo[i % supo.length]; + }).length +} From 8a125d3421de96ba54714e5e02af5f048f309f26 Mon Sep 17 00:00:00 2001 From: jeuk817 <47104203+jeuk817@users.noreply.github.com> Date: Mon, 3 Jun 2019 15:41:55 +0900 Subject: [PATCH 06/14] =?UTF-8?q?feat:=20H=20index,=20=EB=AA=A8=EC=9D=98?= =?UTF-8?q?=EA=B3=A0=EC=82=AC=20=ED=92=80=EC=9D=B4=20(#47)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 190524/circus/hIndex.js | 34 ++++++++++++++++++++++++++++++++++ 190527/circus/exam.js | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 190524/circus/hIndex.js create mode 100644 190527/circus/exam.js diff --git a/190524/circus/hIndex.js b/190524/circus/hIndex.js new file mode 100644 index 0000000..d507e9f --- /dev/null +++ b/190524/circus/hIndex.js @@ -0,0 +1,34 @@ +// 첫번째 +function solution(citations) { + var answer = 0; + while (true) { + if (citations.filter(x => { return x > answer }).length > answer) { + answer += 1; + continue; + } + break; + } + return Math.max.apply(null, citations) === 0 ? 0 : answer; +} + +// 두번째 + +function solution(citations) { + citations.sort((a, b) => b - a).unshift(0); + for (var i = citations.length - 1; i >= 0; i--) { + if (citations[i] >= i) return i; + } +} + +// 세번째 + +function solution(citations) { + citations = citations.sort((a, b) => a - b); + while (true) { + if (citations.findIndex(x => x < citations.length) !== -1) { + citations.shift(); + } else { + return citations.length; + } + } +} \ No newline at end of file diff --git a/190527/circus/exam.js b/190527/circus/exam.js new file mode 100644 index 0000000..a5cac56 --- /dev/null +++ b/190527/circus/exam.js @@ -0,0 +1,19 @@ +function solution(answers) { + var num1 = [1, 2, 3, 4, 5]; + var num2 = [2, 1, 2, 3, 2, 4, 2, 5]; + var num3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; + var results = [0, 0, 0]; + var winer = []; + + answers.forEach((ans, i) => { + if (ans === num1[i % num1.length]) results[0] += 1; + if (ans === num2[i % num2.length]) results[1] += 1; + if (ans === num3[i % num3.length]) results[2] += 1; + }) + + var max = Math.max(...results); + results.forEach((result, i) => { + if (result === max) winer.push(i + 1); + }) + return winer; +} \ No newline at end of file From 008cc1861be5ad82d8091c2ebe51e7a9e13f8fa4 Mon Sep 17 00:00:00 2001 From: gminiy Date: Mon, 3 Jun 2019 15:42:10 +0900 Subject: [PATCH 07/14] [ingleby]190527 algorithm (#48) --- 190527/ingleby/mouigosa.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 190527/ingleby/mouigosa.py diff --git a/190527/ingleby/mouigosa.py b/190527/ingleby/mouigosa.py new file mode 100644 index 0000000..bb4a765 --- /dev/null +++ b/190527/ingleby/mouigosa.py @@ -0,0 +1,24 @@ +def solution(answers): + patternA = [1, 2, 3, 4, 5] + patternB = [2, 1, 2, 3, 2, 4, 2, 5] + patternC = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] + i = 0 + a = 0 + b = 0 + c = 0 + for s in answers : + if patternA[i%5] == s: + a=a+1 + if patternB[i%8] == s: + b=b+1 + if patternC[i%10] == s: + c=c+1 + i = i+1 + answer2 = [a,b,c] + maxt = max(answer2) + answer = [] + i = 1 + for idx in range(len(answer2)): + if answer2[idx] == maxt: + answer.append(idx + 1) + return answer From 291a605b4a9760f6743811b56581503fd1e98ff1 Mon Sep 17 00:00:00 2001 From: SangYun Ha Date: Mon, 3 Jun 2019 15:42:31 +0900 Subject: [PATCH 08/14] =?UTF-8?q?[190527]=20H=20=EC=95=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EC=A6=98=20=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4=20?= =?UTF-8?q?=EC=A0=9C=EC=B6=9C=ED=95=A9=EB=8B=88=EB=8B=A4.=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * H-Index 문제풀이 * H-Index 문제풀이 * 모의고사 문제풀이 --- 190527/H/exam.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 190527/H/exam.py diff --git a/190527/H/exam.py b/190527/H/exam.py new file mode 100644 index 0000000..9fd5582 --- /dev/null +++ b/190527/H/exam.py @@ -0,0 +1,17 @@ +def solution(answers): + person1 = [1, 2, 3, 4, 5] + person2 = [2, 1, 2, 3, 2, 4, 2, 5] + person3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] + count = [0, 0, 0] + result = [] + for idx, answer in enumerate(answers): + if answer == person1[idx % len(person1)]: + count[0] += 1 + if answer == person2[idx % len(person2)]: + count[1] += 1 + if answer == person3[idx % len(person3)]: + count[2] += 1 + for idx, c in enumerate(count): + if c == max(count): + result.append(idx+1) + return result From aba78191206b9435bfe813f9e5c08584931f00a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AC=B5=EC=9D=80=EC=A7=80?= <39726860+mukeunzi@users.noreply.github.com> Date: Mon, 3 Jun 2019 15:42:42 +0900 Subject: [PATCH 09/14] =?UTF-8?q?[mukeunzi]=20190528=20=EB=AA=A8=EC=9D=98?= =?UTF-8?q?=EA=B3=A0=EC=82=AC=20=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4=20(#50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 190527/mukeunzi/MockTest.java | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 190527/mukeunzi/MockTest.java diff --git a/190527/mukeunzi/MockTest.java b/190527/mukeunzi/MockTest.java new file mode 100644 index 0000000..e49f252 --- /dev/null +++ b/190527/mukeunzi/MockTest.java @@ -0,0 +1,46 @@ +import java.util.*; + +class Solution { + public int[] solution(int[] answers) { + int way1[] = new int[]{1, 2, 3, 4, 5}; + int way2[] = new int[]{2, 1, 2, 3, 2, 4, 2, 5}; + int way3[] = new int[]{3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; + int cnt[] = new int[3]; + int max = 0; + int result[]; + List answer = new ArrayList<>(); + + for(int i=0; i Date: Mon, 3 Jun 2019 15:43:06 +0900 Subject: [PATCH 10/14] =?UTF-8?q?[ruby]=20=EB=AA=A8=EC=9D=98=EA=B3=A0?= =?UTF-8?q?=EC=82=AC=20=EB=B3=B4=EB=83=85=EB=8B=88=EB=8B=A4.=20(#52)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * programmers runner * programmers runner * k번째 수 문제풀이 -map 사용해서 slice 로 answer 에 push * refactor : map 중복제거 * h-index solution * ruby 모의고사 문제풀이 * ruby 모의고사 풀이 --- 190521/k_number.js | 6 ------ 190524/ruby/solution.js | 13 +++++++++++++ 190527/ruby/solution.js | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) delete mode 100644 190521/k_number.js create mode 100644 190524/ruby/solution.js create mode 100644 190527/ruby/solution.js diff --git a/190521/k_number.js b/190521/k_number.js deleted file mode 100644 index d49891a..0000000 --- a/190521/k_number.js +++ /dev/null @@ -1,6 +0,0 @@ -const solution = (arr, commands) => { - let answer = commands.map( el => arr.slice(el[0]-1,el[1]).sort(sortFuc)[el[2]-1]) - return answer; -} - -const sortFuc = (a,b) => {return a-b}; \ No newline at end of file diff --git a/190524/ruby/solution.js b/190524/ruby/solution.js new file mode 100644 index 0000000..fd42ca1 --- /dev/null +++ b/190524/ruby/solution.js @@ -0,0 +1,13 @@ +const solution = (c) => { + c.sort((a,b)=>b-a); + for(let i=0; i c[i]){ + return i + }else if(i+1 === c[i]){ + return c[i] + } + } + return c.length +} + +console.log(solution([1,1,3,4,8])) \ No newline at end of file diff --git a/190527/ruby/solution.js b/190527/ruby/solution.js new file mode 100644 index 0000000..6353650 --- /dev/null +++ b/190527/ruby/solution.js @@ -0,0 +1,25 @@ +const solution = (answers) => { + let answer = []; + const a = [1,2,3,4,5]; + const b = [2,1,2,3,2,4,2,5]; + const c = [3,3,1,1,2,2,4,4,5,5]; + let num = [0,0,0]; + + answers.forEach((el, i)=>{ + if(el === a[i%5]){ + num[0] = num[0] + 1; + } + if(el === b[i%8]){ + num[1] = num[1] + 1; + } + if(el === c[i%10]){ + num[2] = num[2] + 1; + } + }) + num.forEach( (el, i) => { + if(el === Math.max(...num)){ + answer.push(i+1) + } + }) + return answer +} \ No newline at end of file From 380f6d3295165572ceb2dd812ff2bb435a482d4f Mon Sep 17 00:00:00 2001 From: nailerHeum Date: Mon, 3 Jun 2019 15:43:23 +0900 Subject: [PATCH 11/14] Nailer Solve programmers supoja problem (#53) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Solve programmers supoja problem https://programmers.co.kr/learn/courses/30/lessons/42840 * Solve snail problem 백준 달팽이 알고리즘 문제 해결 --- 190527/nailer/supoja.py | 31 +++++++++++++++++++++++++++++++ 190530/nailer/snail.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 190527/nailer/supoja.py create mode 100644 190530/nailer/snail.py diff --git a/190527/nailer/supoja.py b/190527/nailer/supoja.py new file mode 100644 index 0000000..4da95b0 --- /dev/null +++ b/190527/nailer/supoja.py @@ -0,0 +1,31 @@ +def solution(answers): + answer = [] + x = 0 + y = 0 + z = 0 + d = {} + ySet = [2, 1, 2, 3, 2, 4, 2, 5] + zSet = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] + for i in list(range(len(answers))): + if answers[i] == i % 5 + 1: + x += 1 + if answers[i] == ySet[i % 8]: + y += 1 + if answers[i] == zSet[i % 10]: + z += 1 + if x==y and y==z: + return [1,2,3] + if x>y and x>z: + return [1] + if y>x and y>z: + return [2] + if z>x and z>y: + return [3] + if x==y and y > z: + return [1, 2] + if y==z and z > x: + return [2, 3] + if z==x and x > y: + return [1, 3] + + return answer diff --git a/190530/nailer/snail.py b/190530/nailer/snail.py new file mode 100644 index 0000000..24e3901 --- /dev/null +++ b/190530/nailer/snail.py @@ -0,0 +1,32 @@ +import sys +from functools import reduce + +a = int(input()) +b = int(input()) +matrix = [[0]*a for i in range(a)] +row = a//2 +column = a//2 +sequence = 1 +sequenceCount = 0 +posiNeg = -1 +answerRow = 0 +answerCol = 0 + +for i in range(a*a): + matrix[row][column] = i+1 + if b == i+1: + answerRow = row + answerCol = column + if sequenceCount == 2*sequence: + sequence += 1 + sequenceCount = 0 + posiNeg *= -1 + sequenceCount += 1 + if sequenceCount <= sequence: + row += posiNeg + else: + column += posiNeg * -1 + +for item in matrix: + print(reduce(lambda x, y: str(x)+' '+str(y), item)) +print(answerRow+1, answerCol+1) From d314a086cd0deec984a4a42ac82c3b8046ec95fc Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 3 Jun 2019 15:43:49 +0900 Subject: [PATCH 12/14] =?UTF-8?q?[Jake]=20190530=20=EB=8B=AC=ED=8C=BD?= =?UTF-8?q?=EC=9D=B4=20=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4=20(#54)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 19년 5월 21일 PS 솔루션 업데이트 프로그래머스 - K번째 수 * fix: 솔루션 파일 이동 * feat: 19년 5월 22일 PS 솔루션 업데이트 프로그래머스 - 가장 큰 수 * feat: 19년 5월 24일 PS 솔루션 업데이트 프로그래머스 - H-index * fix: H-Index 수정 나머지 논문의 포함 범위를 수정(인용 횟수가 h번 미만) * feat: 19년 5월 27일 PS 솔루션 업데이트 프로그래머스 - 모의고사 * feat: 19년 5월 30일 PS 솔루션 업데이트 백준 - 달팽이 --- 190530/jake/1913.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 190530/jake/1913.cpp diff --git a/190530/jake/1913.cpp b/190530/jake/1913.cpp new file mode 100644 index 0000000..bd8beca --- /dev/null +++ b/190530/jake/1913.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; +int n, t; +int arr[999][999]{0,}; + +int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; + +bool valid_location(int y, int x) +{ + return y < n && y >= 0 && x < n && x >= 0 && arr[y][x] == 0; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(NULL); + + cin >> n >> t; + + int num = n * n, d = 0, y = -1, x = 0, ay, ax; + + while(num > 0){ + int dy = dir[d % 4][0], dx = dir[d % 4][1]; + y += dy, x += dx; + while(valid_location(y, x)){ + if(num == t) ay = y, ax = x; + arr[y][x] = num--, y += dy, x += dx; + } + y -= dy, x -= dx; + ++d; + } + + for(int i=0; i Date: Mon, 3 Jun 2019 15:44:08 +0900 Subject: [PATCH 13/14] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A4=20-=20=20=EB=AA=A8=EC=9D=98=EA=B3=A0?= =?UTF-8?q?=EC=82=AC=20=EB=AC=B8=EC=A0=9C=20=ED=92=80=EC=9D=B4=20(#56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 190527/hyodol/mock_test.cpp | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 190527/hyodol/mock_test.cpp diff --git a/190527/hyodol/mock_test.cpp b/190527/hyodol/mock_test.cpp new file mode 100644 index 0000000..4d6c8d5 --- /dev/null +++ b/190527/hyodol/mock_test.cpp @@ -0,0 +1,43 @@ +#include +#include +using namespace std; + +vector solution(vector answers) { + vector > patterns(3); + patterns[0] = {1, 2, 3, 4, 5}; + patterns[1] = {2, 1, 2, 3, 2, 4, 2, 5}; + patterns[2] = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; + + int maxCnt = 0; + vector personCnt(3); + for (int i = 0; i < 3; i++) { + int cnt = 0; + int patternsSize = (int)patterns[i].size(); + for (int j = 0; j < answers.size(); j++) { + if (answers[j] == patterns[i][j % patternsSize]) cnt++; + } + personCnt[i] = cnt; + maxCnt = max(maxCnt, cnt); + } + + vector result; + for (int i = 0; i < 3; i++) { + if (maxCnt == personCnt[i]) result.push_back(i+1); + } + return result; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); + + vector result1 = solution({1, 2, 3, 4, 5}); + for (int num : result1) cout << num << " "; + cout << '\n'; + + vector result2 = solution({1, 3, 2, 4, 2}); + for (int num : result2) cout << num << " "; + cout << '\n'; + + return 0; +} From 7ac73a69acd4c1032dc5938f1982c4df775a5ce6 Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Mon, 3 Jun 2019 15:48:44 +0900 Subject: [PATCH 14/14] BOJ 1913 snail (#60) --- 190530/honux/1913-snail.cpp | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 190530/honux/1913-snail.cpp diff --git a/190530/honux/1913-snail.cpp b/190530/honux/1913-snail.cpp new file mode 100644 index 0000000..9983edf --- /dev/null +++ b/190530/honux/1913-snail.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include + +using namespace std; +int dr[] = { -1, 0, 1, 0 }; +int dc[] = { 0, 1, 0, -1 }; + + +int main() { + int n; + scanf("%d", &n); + vector > m(n); + map> nmap; + for (int i = 0; i < n; i++) { + m[i].resize(n); + } + + int num = 1; + int row = n / 2; + int col = row; + double w = 1; + m[row][col] = num; + int vec = 0; + + bool loop = true; + while (loop) { + for (int i = 0; i < (int) w; i++) { + num++; + if (num > n * n) { + loop = false; + break; + } + row += dr[vec]; + col += dc[vec]; + m[row][col] = num; + nmap[num] = make_pair(row + 1, col + 1); + } + vec = (vec + 1) % 4; + w += 0.5; + } + + for (auto v : m) { + for (auto n : v) { + printf("%d ", n); + } + printf("\n"); + } + + int x; + scanf("%d", &x); + printf("%d %d\n", nmap[x].first, nmap[x].second); + return 0; +}