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/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/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/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; +} 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/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/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 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 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; +} 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 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 +} 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; iy 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/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 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/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; +} 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 +#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<