diff --git a/g0rnn/README.md b/g0rnn/README.md index d24e2fc..a9f8bf1 100644 --- a/g0rnn/README.md +++ b/g0rnn/README.md @@ -7,5 +7,7 @@ | 3차시 | 2024.10.04 | 문자열 | [잃어버린 괄호](https://www.acmicpc.net/problem/1541) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/9 | | 4차시 | 2024.10.11 | 브루트포스 | [영화감독 숌](https://www.acmicpc.net/problem/1436) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/15 | | 5차시 | 2024.11.01 | BFS/DFS | [연구소](https://www.acmicpc.net/problem/14502) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/17 | +| 6차시 | 2024.11.06 | 구현 | [통계학](https://www.acmicpc.net/problem/2108) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/23 | +| 7차시 | 2024.11.25 | 구현 | [팰린드롬 만들기](https://www.acmicpc.net/problem/1213) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/31 | --- diff --git "a/g0rnn/\352\265\254\355\230\204/7-g0rnn.cpp" "b/g0rnn/\352\265\254\355\230\204/7-g0rnn.cpp" new file mode 100644 index 0000000..e620c1a --- /dev/null +++ "b/g0rnn/\352\265\254\355\230\204/7-g0rnn.cpp" @@ -0,0 +1,70 @@ +#include +using namespace std; + +int alpha[26] = { + 0, +}; +string name; +int n; + +// When palindrome is 'ABABA', half is 'ABA' and n.length = 5 +void print_palindrome(string half) +{ + cout << half; + // subtract 1 when it's odd. + int len = half.length() - n % 2; + for (int i = len - 1; i >= 0; i--) + { + cout << half[i]; + } +} + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + + cin >> name; + n = name.length(); + + // init alpha[] + for (int i = 0; i < n; i++) + { + int index = name[i] - 'A'; + alpha[index]++; + } + + int i; + string ret = ""; + for (i = 0; i < 26; i++) + { + // push each alphabet until possible + while (alpha[i] > 1) + { + ret = ret + (char)(i + 'A'); + alpha[i] -= 2; + } + } + + // when length is odd + if (n % 2 == 1) + { + i = 0; + while (alpha[i] == 0) + i++; + ret = ret + (char)(i + 'A'); + alpha[i] -= 1; + } + + for (i = 0; i < 26; i++) + { + if (alpha[i] > 0) + { + cout << "I'm Sorry Hansoo\n"; + return 0; + } + } + + print_palindrome(ret); + return 0; +}