정신과 시간의 방

코딩테스트/문제풀이 36

카테고리 설명
  • 문제 풀이#include using namespace std;long long a;long long b;int main(){ cin >> a >> b; if (a

  • 문제 풀이입력받은 값을 배열에 쭉 저장한 뒤, 두 값이 합쳐졌을 때 x가 되는 경우를 판단해야 하는 문제이다. 뭔가 답이 알듯말듯해서 혼자 고민하다가 다른 분의 풀이(https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x03/solutions/3273.cpp) 를 참고했다. 이미 너무 깔끔한 코드인데 개인적으로 조건문 내부에서 사칙연산을 그대로 넣는 걸 좋아하지 않아서 value 변수로 따로 빼주었다. #include using namespace std;int a[1000001] = {};bool occur[2000001];int n, x;int main(void) { ios::sync_with_stdio(0); cin.tie(0..

  • 문제 풀이#include using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); string n = ""; int arr[10] = { 0, }; cin >> n; for (char c : n) { arr[c - '0']++; } arr[6] = (arr[6] + arr[9] + 1) / 2; int max = 0; for (int i = 0; i  문제를 읽어보면서 2가지를 떠올렸다. 1. 입력받은 값중에 가장 많이 등장한 값의 수가 필요한 세트의 수가 된다.2. 6과 9는 서로 호환가능하기 때문에 한 세트에 2개까지 사용할 수 있다. 이를 따로 처리해주어야 한다. 따라서 우선 string으로 값을 받아서, 배열의 인덱스를 입..

  • 문제 풀이#include using namespace std;int n, input, y_total, m_total;int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i > input; // 각 통화 시간에 대해 영식 요금제와 민식 요금제를 개별적으로 계산 y_total += (input / 30 + 1) * 10; // 영식 요금제 요금 계산 m_total += (input / 60 + 1) * 15; // 민식 요금제 요금 계산 } if (y_total  메모각 통화 시간에 대해서 2개의 요금제에 대해서 개별적으로 요금을 계산해야 한다는 점..

  • 문제 문제풀이#include #include #include using namespace std;int main(){ ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); int number = 0, minValue = 0; int sum = 0; vector odds; for (int i = 0; i > number; if (number % 2 == 1) { odds.push_back(number); sum += number; } } if (sum == 0) { sum = -1; cout  더 간결한 풀이 (출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x02/sol..

  • 문제 풀이#include using namespace std;int main(){ ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); int input = 0; for (int i = 0; i > input; if (input == 0) { cnt++; } } switch (cnt) { case 0: cout  더 나은 풀이 (출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x02/solutions/2490.cpp)// Authored by : wogha95// Co-authored by : BaaaaaaaaaaarkingDog// http://boj.kr/..

  • 문제  답안- vector, sort를 쓴 경우#include #include #include using namespace std;vector arr;int input;int main(){ ios::sync_with_stdio(0); cin.tie(0); for (int i = 0; i > input; arr.push_back(input); } sort(arr.begin(), arr.end()); for (int i = 0; i   - swap으로 직접 정렬#include using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int arr[3] = { 0, }; for (int i = 0; i > arr..

  • 문제 풀이#include #include using namespace std;int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); deque dq; int n = 0, command = 0, input = 0; cin >> n; for (int i = 0; i > command; switch (command) { case 1: cin >> input; dq.push_front(input); break; case 2: cin >> input; dq.push_back(input); break; case 3: if (false == dq.empty()) { cout   메모가볍게 덱을 사용해..