끄적끄적 코딩
article thumbnail
[C++] 백준 1032번 명령 프롬프트
알고리즘 2019. 9. 9. 20:06

문자열 처리 문제입니다. 문자열 끼리 비교해서 다른 부분을 배열에서 체크를 해두었습니다. 그리고 체크된 부분은 ?로 출력해서 문제를 풀었습니다. #include #include #include using namespace std; int main(int argc, char *argv[]) { int n; int check[60]; string s[60]; memset(check, 0, sizeof(check)); cin >> n; cin >> s[0]; for (int i = 1; i > s[i]; for (int j = 0; j < s[0].length(); ++j) { if (s[i][j] != s[i - 1][j]) { check[j] = 1; } } } for (in..

article thumbnail
[C++] 백준 1100번 하얀 칸
알고리즘 2019. 9. 9. 19:56

체스판에서 하얀칸에 말이 몇마리 있는지 찾는 문제입니다. 0,0은 하얀칸이며, F는 말입니다. 하얀색과 검정색이 차례대로 나오므로 하얀칸을 구하기위해서 (i+j) % 2 == 0이면 하얀칸입니다. (i, j는 8*8배열에 대한 반복문) 하얀칸일 때 'F'면 카운트를 증가해줬습니다. #include #include #include using namespace std; int main(int argc, char *argv[]) { int count = 0; string s; for (int i = 0; i > s; for (int j = 0; j < 8; ++j) { if ((i + j) % 2 == 0 && s[j] == 'F') { ++count; } } } cout

article thumbnail
[C++] 백준 10808번 알파벳 개수
알고리즘 2019. 9. 9. 19:48

알파벳 개수를 출력하는 문제입니다. 알파벳 개수만큼 배열을 만들고 for문을 통해서 문자 하나하나에 대해서 체크를 합니다. 소문자만 입력받기 때문에 가장 작은 글자는 a입니다. a는 아스키코드로 97이므로 문자 -97 한 배열위치를 +1해줍니다. 이를 통해 각 알파벳의 개수를 셀수있습니다. #include #include #include using namespace std; int main(int argc, char *argv[]) { int alpha[26]; string s; memset(alpha, 0, sizeof(alpha)); cin >> s; for (int i = 0; i < s.length(); ++i) { ++alpha[s[i] - 97]; } for (int i = 0; i < 26;..

article thumbnail
[C++] 백준 2743번 단어 길이 재기
알고리즘 2019. 9. 9. 19:41

문자열 문제입니다. string으로 문자를 받고 length()를 출력해주었습니다. #include #include using namespace std; int main(int argc, char *argv[]) { string s; cin >> s; cout

article thumbnail
[C++] 백준 1158번 조세퍼스 문제
알고리즘 2019. 9. 9. 15:28

큐를 통해서 풀었습니다. 모든 값들을 큐에 차례대로 넣고 K-1만큼 큐에서 빼서 뒤로 보내고 K번째는 출력하고 pop해줍니다. #include #include #include #include using namespace std; int main(int argc, char *argv[]) { int n, t; int temp; queue q; cin >> n >> t; for (int i = 1; i

article thumbnail
[C++] 백준 2312번 수 복원하기
알고리즘 2019. 9. 9. 11:36

소인수를 구하는 문제입니다. n을 2~n까지 나눠봅니다. 나누어 떨어지면 안 나누어 떨어질 때까지 나눕니다. 그리고 나눈 횟수를 배열[나눈 수]에 저장합니다. #include #include #include using namespace std; int main(int argc, char *argv[]) { int n; int temp; int ts; int arr[100010]; cin >> ts; while (ts--) { memset(arr, 0, sizeof(arr)); cin >> n; temp = n; for (int i = 2; i

article thumbnail
[C++] 백준 2448번 별 찍기 - 11
알고리즘 2019. 9. 9. 11:24

분할정복 문제입니다. * * * ***** 위의 모양이 반복되는 것을 확인할 수 있습니다. n과 0, 0을 넣고 solve함수를 실행합니다. n이 1이되면 위의 모양을 그대로 넣어줍니다. 1이 아니면 n/2를 해주고, y와 x에 대해서 위 가운데, 왼쪽 아래, 오른쪽 아래로 나누어서 solve 함수를 실행합니다. 이를 반복하여서 map에 *을 전부 그리고 출력합니다. #include #include #include using namespace std; char DB[3][6] = { " * ", " * * ", "*****" }; char map[4000][8000]; void solve(int n, int y, int x) { if (n == 1) { for (int i = 0; i < 3; i++) ..

article thumbnail
[C++] 백준 2902번 KMP는 왜 KMP일까?
알고리즘 2019. 9. 9. 08:35

문자의 앞글자만 따오는 문제입니다. string s1에 입력을 받고 첫글자를 s2에 넣습니다. 그리고 '-'이 나올때마다 그 다음 글자를 s2에 추가로 넣습니다. #include #include #include #include using namespace std; int main(int argc, char *argv[]) { string s; string s2; cin >> s; s2 = s[0]; for (int i = 0; i < s.length(); ++i) { if (s[i] == '-') { s2 += s[i + 1]; } } cout

검색 태그