Skip to content

Commit

Permalink
Merge pull request #31 from AlgoLeadMe/7-g0rnn
Browse files Browse the repository at this point in the history
7-g0rnn
  • Loading branch information
g0rnn authored Nov 29, 2024
2 parents b9f5e94 + d5d7e37 commit fe4e907
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions g0rnn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

---
70 changes: 70 additions & 0 deletions g0rnn/κ΅¬ν˜„/7-g0rnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <iostream>
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;
}

0 comments on commit fe4e907

Please sign in to comment.