정신과 시간의 방

코딩테스트 128

카테고리 설명
  • 문제 풀이#include #include using namespace std;int main() { int n = 0; cin >> n; queue st; string str; for (int i = 0; i > str; if (str == "push") { int input = 0; cin >> input; st.push(input); } else if (str == "pop") { if (false == st.empty()) { cout

  • 문제 풀이#include #include using namespace std;int main() { int n = 0; cin >> n; stack st; string str; for (int i = 0; i > str; if (str == "push") { int input = 0; cin >> input; st.push(input); } else if (str == "pop") { if (false == st.empty()) { cout   메모front, pop 함수를 실행하기 전에 empty 함수로 스택 내부가 비어있는지 확인하는 것을 주의해야 한다.

  • 문제 풀이#include using namespace std; int factorial(int t) { // 초기값이 0이면 곱한 결과가 0이 되므로 반드시 1로 초기화 해주어야 한다. int result = 1; // 해당 값부터 하나씩 줄여가며 곱해간다. for (int i = t; i > 0; i--) { result *= i; } return result;} int main() { int n, k; cin >> n >> k; int result = factorial(n) / (factorial(k) * factorial(n - k)); cout  메모이항 계수를 구하기 위해 팩토리얼을 사용했다.팩토리얼 공식은 facto..

  • 문제 풀이#include #include #include using namespace std;int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); while (true) { string str = ""; getline(cin, str); if (str == ".") { break; } int flag = 0; stack s; int strLength = str.length(); for (int i = 0; i  다시 풀이 (24-11-10)#include #include #include using namespace std;int main(){ ios::sync_with_stdi..

  • 문제 풀이#include using namespace std;int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); int n = 0, m = 0, totalSum = 0, resultMax = 0; int arr[101] = {}; cin >> n >> m; for (int i = 0; i > arr[i]; } for (int i = 0; i resultMax) { resultMax = totalSum; } } } } cout   메모이 문제 역시 브루트 포스 문제에 해당한다. 모든 경우의 수를 다 따져보는데다 3중 for문을 사용하는 경우가 거의 없어서 성능적으로 문제가 되지..

  • 문제 풀이#include #include #include #include using namespace std;bool compare(string str1, string str2){ // 길이가 같은 경우 사전 순으로 정렬하고 if (str1.size() == str2.size()) { return str1 > n; vector str; string input; for (int i = 0; i > input; str.push_back(input); } sort(str.begin(), str.end(), compare); str.erase(unique(str.begin(), str.end()), str.end()); vector::iterator iter; for (iter = str.begin(); i..

  • 문제 풀이#include #include #include #include using namespace std;bool compare(paira, pairb){ return a.first > n; pair member; vector> members; for (int i = 0; i > member.first >> member.second; members.push_back(member); } stable_sort(members.begin(), members.end(), compare); for (int i = 0; i  메모이전에 풀었던 pair와 vector의 sort기능을 사용한 정렬문제와 비슷하게 pair와 stable_sort를 사용하는 문제다.stable sort란 기존 데이터의 순서를 손상시키지..

  • 문제 풀이#include #include #include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n = 0; cin >> n; vector> points(n); for (int i = 0; i > points[i].second >> points[i].first; } sort(points.begin(), points.end()); for (int i = 0; i  메모아래 링크의 좌표 정렬하기 1 문제와 동일한데, 정렬 기준만 다르기 때문에 입력과 출력시 y와 x의 순서만 바꿔주었다.pair와 sort에 대한 내용은 아래 포스팅에서 언급했다.https://rise..