끄적끄적 코딩
article thumbnail
[C++] 백준 10451번 순열 사이클
알고리즘 2019. 9. 30. 18:52

사이클을 확인하는 문제입니다. DFS를 통해서 각 노드에서 이어진 노드를 전부 방문처리를 해주었습니다. 이어진 노드끼리는 방문처리 과정에서 같은 노드라고 체크해주었습니다. ex) 1, 3, 4 싸이클, 2, 5 싸이클 visit[1] = 1 visit[3] = 1 visit[4] = 1 visit[2] = 2 visit[5] = 2 위와 같이 각 싸이클에 해당 넘버를 지정해서 체크해주고 최종적으로 넘버를 통해서 싸이클이 몇개인지 확인했습니다. #include #include #include #include using namespace std; int ts; int n; int num; int c = 1; int cycle; int visit[1010]; vector v; int DFS(int cur) {..

article thumbnail
[C++] 백준 10699번 오늘 날짜
알고리즘 2019. 9. 28. 16:53

오늘 날짜를 출력하는 문제입니다. #include #include #include using namespace std; int main(int argc, char *argv[]) { struct tm *t; string s = ""; time_t timer; timer = time(NULL); t = localtime(&timer); s += to_string(t->tm_year + 1900); s += "-"; if (t->tm_mon + 1 tm_mon + 1); s += "-"; if (t->tm_mday + 1 tm_mday); cout

article thumbnail
[C++] 백준 1547번 공
알고리즘 2019. 9. 28. 03:57

3개의 컵에서 첫번째 컵에 공을 넣고 시작합니다. 2개의 컵의 위치를 N번 바꿨을때 최종적으로 공을 가지고 있는 컵을 출력하는 문제입니다. swap함수를 만들어주어서 문제를 해결하였습니다. #include using namespace std; int n; int x, y; int ball[4] = { 0, 1, 0, 0 }; void swap(int x, int y) { int temp; temp = ball[x]; ball[x] = ball[y]; ball[y] = temp; } int main(int argc, char *argv[]) { cin >> n; for (int i = 1; i > x >> y; swap(x, y); } for (int i = 1; i

article thumbnail
[C++] 백준 16360번 Go Latin
알고리즘 2019. 9. 27. 17:58

문자열 문제입니다. 뒤의 문자를 확인하여, 그 문자에 해당하는 끝자리로 바꿔주면 됩니다. #include using namespace std; int n; string s; char e[12] = { 'a', 'i', 'y', 'l', 'n', 'o', 'r', 't', 'u', 'v', 'w', 'e' }; void add(char c) { if (c == 'e' && s[s.length() - 2] != 'n'){ c = ' '; } switch (c) { case 'a': s += "s"; break; case 'i': s += "os"; break; case 'y': s[s.length() - 1] = 'i'; s += "os"; break; case 'l': s += "es"; break; ca..

article thumbnail
[C++] 백준 2914번 저작권
알고리즘 2019. 9. 27. 14:48

n과 m을 입력받고 n * (m - 1) + 1을 출력해줍니다. #include using namespace std; int main(int argc, char* argv[]) { int n, m; cin >> n >> m; cout

article thumbnail
[C++] 백준 11942번 고려대는 사랑입니다.
알고리즘 2019. 9. 27. 14:44

고려대학교를 출력하면 됩니다. #include using namespace std; int main(int argc, char *argv[]) { cout

article thumbnail
[C++] 백준 5598번 카이사르 암호
알고리즘 2019. 9. 27. 13:27

문자를 왼쪽으로 3칸밀어서 출력하는 문제입니다. string에 문자를 입력받고 문자하나씩 -3을 해줍니다. A~Z를 까지 있으므로 A는 아스키코드로 65입니다. 65보다 작아진 경우 26을 더해줘서 뒤로 갈수 있게 해줍니다. 바뀐 문자를 출력해줍니다. #include #include #include #include using namespace std; int main(int argc, char* argv[]) { string s; cin >> s; for (int i = 0; i < s.length(); ++i) { s[i] = s[i] - 3; if (s[i] < 65) { s[i] += 26; } cout

article thumbnail
[C++] 백준 2799번 블라인드
알고리즘 2019. 9. 26. 23:30

블라인드가 5개의 모양이 있습니다. 이때 각 모양이 몇개가 있는지 출력하는 문제입니다. 블라인드 모양 전부를 비교하지 않고 각줄의 첫번째 글자만 비교했습니다. #include #include #include using namespace std; int M, N; int blind[5] = { 0, }; char map[510][510]; string s; int main(int argc, char *argv[]) { cin >> M >> N; for (int i = 0; i > s; for (int j = 0; j < s.length(); ++j) { map[i][j] = s[j]; } } for (int i = 1; i < M * 5 + 1; i += 5) ..

검색 태그