Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7-g0rnn #31

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Comment on lines +42 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄λ ‡κ²Œ 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;
}