1. 프로그래머스 기출 문제

This commit is contained in:
이형구 2025-04-08 13:51:41 +09:00
parent 6cfea47a0f
commit 80521c093a
8 changed files with 161 additions and 0 deletions

BIN
과제2폴더/2-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

14
과제2폴더/2-1.txt Normal file
View File

@ -0,0 +1,14 @@
#include <string>
#include <vector>
using namespace std;
int solution(int n, int k) {
int answer = 0;
// 총액
answer = n * 12000;
answer += (k - (n / 10)) * 2000;
return answer;
}

BIN
과제2폴더/2-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

21
과제2폴더/2-2.txt Normal file
View File

@ -0,0 +1,21 @@
#include <string>
#include <vector>
using namespace std;
int solution(vector<vector<int>> board, int k) {
int answer = 0;
for (int i=0; i<board.size(); i++)
{
for (int j=0; j<board[i].size(); j++)
{
if (i+j <= k)
{
answer += board[i][j];
}
}
}
return answer;
}

BIN
과제2폴더/2-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

91
과제2폴더/2-3.txt Normal file
View File

@ -0,0 +1,91 @@
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
static bool comp(pair<int, int>& a, pair<int, int>& b){
return a.second > b.second;
}
int solution(int a, int b, int c, int d) {
int answer = 0;
map<int,int> m;
m[a]++;
m[b]++;
m[c]++;
m[d]++;
vector<pair<int, int>> v(m.begin(), m.end());
sort(v.begin(), v.end(), comp);
bool n3 = false;
bool n2 = false;
bool n1 = false;
bool n0 = false;
for (auto it = v.begin(); it != v.end(); ++it) {
switch(it->second)
{
// 4개 같음
case 4:
answer = 1111 * it->first;
break;
// 3개 같음
case 3:
answer = 10 * it->first;
n3 = true;
break;
// 2개 같음
case 2:
// 2개 이후 2개
if (n2)
{
answer = (answer + it->first) * abs(answer - it->first);
break;
}
answer = it->first;
n2 = true;
break;
// 1개 같음
case 1:
// 3개 이후 1개
if (n3)
{
answer = (answer + it->first) * (answer + it->first);
break;
}
// 2개 이후 1개
if (n2)
{
// 2개 이후 1개 이후 1개
if (n1)
{
answer = answer * - it->first;
break;
}
answer = - it->first;
n1 = true;
break;
}
// 1개 이후 1개
if (n1)
{
answer < it->first ? answer : it->first;
break;
}
answer = it->first;
n1 = true;
break;
}
}
return answer;
}

BIN
과제2폴더/2-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

35
과제2폴더/2-4.txt Normal file
View File

@ -0,0 +1,35 @@
#include <string>
#include <vector>
using namespace std;
int solution(vector<vector<int>> dots) {
int answer = 0;
// 뭐여 실수만 되네?
double dx = dots[0][0] - dots[1][0];
double dy = dots[0][1] - dots[1][1];
double dx2 = dots[2][0] - dots[3][0];
double dy2 = dots[2][1] - dots[3][1];
if (dx/dy == dx2/dy2)
return 1;
dx = dots[0][0] - dots[2][0];
dy = dots[0][1] - dots[2][1];
dx2 = dots[1][0] - dots[3][0];
dy2 = dots[1][1] - dots[3][1];
if (dx/dy == dx2/dy2)
return 1;
dx = dots[0][0] - dots[3][0];
dy = dots[0][1] - dots[3][1];
dx2 = dots[1][0] - dots[2][0];
dy2 = dots[1][1] - dots[2][1];
if (dx/dy == dx2/dy2)
return 1;
return answer;
}