코딩/백준 42

[백준] 실버5 2941번: 크로아티아 알파벳 C++ / string의 replace

https://www.acmicpc.net/problem/2941 string.replace(교체하고 싶은 문자열의 위치, 교체하고 싶은 문자열의 길이, 새로운 문자열) #include #include using namespace std;void changeAlpha(string &word, string toFind, string toChange) { int idx = 0; while (true) { auto pos = word.find(toFind, idx); if (pos == string::npos) break; word.replace(pos, toFind.size(), toChange); idx = pos; }}void changeWord(string &word) { changeAlph..

코딩/백준 2024.12.06

[백준] 골드5 14503번: 로봇청소기 C++

https://www.acmicpc.net/problem/14503 간단한 구현문제맞왜틀: 시계방향이 아닌 반시계방향으로 돌리기 #include #include using namespace std;struct Node { int y, x, d; };int N, M;vector> map;Node start;int direct[4][2] = { -1, 0, 0, 1, 1, 0, 0, -1,};int main() { cin >> N >> M; map.assign(N, vector(M, 0)); cin >> start.y >> start.x >> start.d; for (int i = 0; i > map[i][j]; } } int cnt = 0; while (true) { // 1. 현재 칸이 아직 청소되..

코딩/백준 2024.12.06

[백준] 16928번: 뱀과 사다리 게임 C++

https://www.acmicpc.net/problem/16928 테케 36%에서 틀린다면, 사다리나 뱀으로 이동한 뒤에 visited도 체크 해 줬는지 확인해보자. #include #include #include using namespace std;int N, M;int dice[6] = { 1, 2, 3, 4, 5, 6 };unordered_map leather;unordered_map snake;vector visited(101, 1e9);void bfs(int start) { queue q; visited[start] = 1; q.push(start); while (!q.empty()) { int now = q.front(); q.pop(); for (int i = 0; i 100) co..

코딩/백준 2024.10.11

[백준] 골드4 1806번: 부분합 C++

https://www.acmicpc.net/problem/1806 투포인터 문제.71%에서 틀렸습니다가 나온다면 마지막 원소를 고려하지 않은 것. #include #include #include using namespace std;int N, S;vector arr;int main() { cin >> N >> S; arr.assign(N, 0); for (int i = 0; i > arr[i]; } arr.push_back(0); int i = 0; int j = 0; int sum = arr[0]; int minLen = 1e9; do { if (sum >= S) { minLen = min(minLen, j - i + 1); sum -= arr[i]; i++; } if (sum

코딩/백준 2024.10.08