전체 글(334)
-
[BOJ] 10804번 : 카드 역배치
1. problem :https://www.acmicpc.net/problem/10804 2. solution 1 :nums = [i+1 for i in range(20)] n = 1 while (n > 0): n -= 1 start_idx,end_idx = map(int,input().split()) nums = nums[:start_idx-1] + list(reversed(nums[start_idx-1:end_idx])) + nums[end_idx:] print(' '.join(map(str,nums)))stl reverse를 이용한 풀이다. 3. solution 2 :#include using namespace std;int num[21];// 카드를 역순으로 놓는 함수void..
2024.08.12 -
[BOJ] 1267번 : 핸드폰 요금
1. problem :https://www.acmicpc.net/problem/1267 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; int young = 0; int minS = 0; while (N--) { int x; cin >> x; int young_r = x / 30; int min_r = x / 60; young += (young_r + 1)* 10; minS += (min_r + 1) * 15; } if (young 29와 59로 나누었을 때 error가 났다. 이때, 30과 60으로 나누는 대신, 기존값에 무조건 ..
2024.08.12 -
[BOJ] 4949번 : 균형잡힌 세상
1. problem : https://www.acmicpc.net/problem/4949 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); while (true) { string words; stack s; getline(cin, words); bool isBalanced = true; if (words == ".") break; for (auto c : words) { if (c == '[' || c == '(') s.push(c); else if (c == ']' || c == ')') { if (s.empty()) { // 예외처리 : stack이 비..
2024.08.08 -
[BOJ] 6198번 : 옥상 정원 꾸미기
1. problem : https://www.acmicpc.net/problem/6198 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; stack s; long long ans = 0; while (N--) { int height; cin >> height; while (!(s.empty()) && s.top() ans를 while문안에서 더해주다가 틀렸다. 이때가 성립할 때는 감소하다가 증가하는 포인트가 있어야 성립한다. 따라서, while문 밖으로 ans를 빼주어야 한다.
2024.08.07 -
[BOJ] 5430번 : AC
1. problem :https://www.acmicpc.net/problem/5430 2. solution 1 :#include using namespace std;void parse(string& input, deque& D) { int cur = 0; for (int i = 1; i + 1 & d) { cout > T; while (T--) { deque D; int rev = 0; string op; bool isWrong = false; int n; string input; cin >> op; cin >> n; cin >> input; parse(input, D); for (char c : op) { if (c == 'R') { rev = 1 - rev; } ..
2024.08.07 -
[BOJ] 1021번 : 회전하는 큐
1. problem :https://www.acmicpc.net/problem/1021 2. solution 1 :#include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int ans = 0; int N, M; cin >> N >> M; deque D; for (int i = 1; i > x; deque dq2(D); deque dq3(D); while (true) { if (dq2.front() != x) { count2++; dq2.push_back(dq2.front()); dq2.pop_front(); } else { dq2.pop_front(); brea..
2024.08.07