본문 바로가기
반응형

C++162

[백준/BOJ] 5585번 - 거스름돈 (C++) 문제 링크 코드 #include using namespace std; int arr[] = {500, 100, 50, 10, 5, 1}; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int n, cnt = 0; cin >> n; n = 1000 - n; for (int i = 0; i < 6; i++) { cnt += n / arr[i]; n %= arr[i]; } cout 2022. 3. 24.
[백준/BOJ] 5397번 - 키로거 (C++) 문제 링크 코드 #include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int n; string s; cin >> n; while (n--) { list L; auto t = L.begin(); cin >> s; for (auto c : s) { switch (c) { case '': if (t != L.end()) t++; break; case '-': if (t != L.begin()) { t--; // 앞의 글자를 지움 t = L.erase(t); // erase - t가 가리키는 값을 제거, 그 다음 원소의 위치를 반환 } break; default: L.insert(t, c); } } for (auto.. 2022. 3. 24.
[백준/BOJ] 5355번 - 화성 수학 (C++) 문제 링크 코드 #include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int t; double n; string s; cin >> t; while (t--) { cin >> n; getline(cin, s); for (auto c : s) { if (c == '@') n *= 3; if (c == '%') n += 5; if (c == '#') n -= 7; } cout 2022. 3. 24.
[백준/BOJ] 4963번 - 섬의 개수 (C++) 문제 링크 코드 #include using namespace std; #define X first #define Y second int h, w; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int i, j; while (1) { int board[51][51] = { 0, }; bool vis[51][51] = { 0, }; int cnt = 0; cin >> w >> h; if (w == 0 && h == 0) break; for (i = 0; i < h; i++) for (j = 0; j < w; j++.. 2022. 3. 24.
[백준/BOJ] 4949번 - 균형잡힌 세상 (C++) 문제 링크 코드 #include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); string line; while (1) { getline(cin, line); if (line == ".") break; int bal = 1; stack ST; for (auto c : line) { if (c == '(' || c == '[') ST.push(c); else if (c == ')') { if (ST.empty() || ST.top() != '(') { bal = 0; break; } ST.pop(); } else if (c == ']') { if (ST.empty() || ST.top() != '[') { bal = 0.. 2022. 3. 24.
[백준/BOJ] 4344번 - 평균은 넘겠지 (C++) 문제 링크 코드 #include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout > n; while (n--) { cin >> student; sum = 0, cnt = 0; vector score; for (i = 0; i > s; score.push_back(s); sum += s; } avg = (double)sum / student; for (i = 0; i avg) cnt++; rate = (double)cnt / student; cout 2022. 3. 23.
[백준/BOJ] 3273번 - 두 수의 합 (C++) 문제 링크 코드 #include using namespace std; int a[2000001]; int occur[2000001]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int i, n, x, cnt = 0; cin >> n; for (i = 0; i > a[i]; cin >> x; for (i = 0; i a[i] && occur[x-a[i]]) cnt++; else occur[a[i]] = 1; } cout 2022. 3. 23.
[백준/BOJ] 3135번 - 라디오 (C++) 문제 링크 코드 #include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int A, B, N, t, ans; cin >> A >> B >> N; ans = abs(A - B); while (N--) { cin >> t; ans = min(abs(t - B) + 1, ans); } cout 2022. 3. 23.
[백준/BOJ] 3062번 - 수 뒤집기 (C++) 문제 링크 코드 #include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int t, n, r, sum; cin >> t; while (t--) { cin >> n; sum = n; r = 0; while (n) { r *= 10; r += n % 10; n /= 10; } sum += r; string s = to_string(sum); reverse(s.begin(), s.end()); cout 2022. 3. 23.
[백준/BOJ] 3059번 - 등장하지 않는 문자의 합 (C++) 문제 링크 코드 #include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int t, ans; string s; cin >> t; while (t--) { ans = 2015; cin >> s; sort(s.begin(), s.end()); s.erase(unique(s.begin(),s.end()),s.end()); for (auto c : s) ans -= c; cout 2022. 3. 23.
반응형