-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ§μνμ λλ‘ μ‘°κΈ μ¬μ΄ νΈμΈκ±΄ λ§λκ² κ°λ€μ
νλ²λ§μ λ§μΆλ €κ³ νλλ°... μμ£Ό μ¬μν λ¬Έμ λ‘ 1νΈλ§μ μ±κ³΅μ μ€ν¨νλ€μ
λ€μ λμ€λ μ μ½λ 보면 μμκ² μ§λ§,
I'm Sorry Hansooλ₯Ό μΆλ ₯νκ³ λμ
return 0; μ μνκ³ break;λ₯Ό ν΄λ²λ €μ νλ Έμλ€μ..
(μ λ 30λΆμ λ κ±Έλ¦°κ² κ°μ΅λλ€)
그리κ³
c - 'A'
c + 'A'
μ΄λ° ννμ μλ μλ μ‘°κΈ λΆμμ°μ€λ½λ€κ³ μκ°νκ³ ,
μ€μ μμ μ¬μ©νκΈ° μ΄λ €μ λλ° μ΄μ μ μ°κ²λ κ² κ°μμ κΈ°λΆμ΄ μ’μ΅λλ€.
μ μ½λμ κ· νΈλ μ½λ μ°¨μ΄λ
1. νμ μ²λ¦¬
2. μΆλ ₯ λ λλ¨Έμ§ μ λ°μ μΆλ ₯νλ λ°©μ
μ΄μ λμΈ λ―νκ³ μ 체μ μΈ κ΅¬μ‘°λ λΉμ·νλ€μ
κ³ μνμ
¨μ΅λλ€.
CPP CODE
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int flag[26] = { 0, };
int main() {
string str;
cin >> str;
for (char c : str) {
flag[c - 'A']++;
}
string result;
char odd = '\0';
for (int i = 0; i < 26; i++) {
if (flag[i] % 2 == 1) {
if (odd != '\0') {
cout << "I'm Sorry Hansoo";
return 0;
}
else odd = i + 'A';
}
int len = flag[i] / 2;
while (len--) {
result += i + 'A';
}
}
cout << result;
if (odd != '\0') cout << odd;
reverse(result.begin(), result.end());
cout << result;
return 0;
}
while (alpha[i] > 1) | ||
{ | ||
ret = ret + (char)(i + 'A'); | ||
alpha[i] -= 2; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄λ κ² 2κ°μ© λΉΌλ λ°©λ²μ΄ μμκ΅°μ
μ λ μ λ°κΉμ§λ§ λΉΌλ λ°©μΌλ‘ νλλ° λ€μν λ°©λ²μ μκ²λμ΄μ μ’λ€μ
μ λ νμ΄λ λ μ¬λ Έλλ° μλ° μλ ¨λ μ΄μλ‘ κ²μν΄κ°λ©΄μ νμμ΅λλ€. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from collections import Counter
def make_palindrome(name):
# Step 1: λ¬Έμ λΉλ κ³μ°
# μ
λ ₯λ λ¬Έμμ΄μμ κ° λ¬Έμκ° λͺ λ² λμ€λμ§ μΈμ΄μ€
counter = Counter(name)
# Step 2: νμ κ° λ¬Έμλ₯Ό μ°ΎκΈ°
# νμ κ°μμ λ¬Έμλ₯Ό μ μ₯ν 리μ€νΈ μμ±
odd_chars = []
for char, count in counter.items():
if count % 2 == 1: # νμ κ°μμΈ κ²½μ°
odd_chars.append(char)
# Step 3: νμ κ° λ¬Έμκ° 2κ° μ΄μμ΄λ©΄ ν°λ¦°λ둬 μμ± λΆκ°
if len(odd_chars) > 1:
return "I'm Sorry Hansoo"
# Step 4: ν°λ¦°λ둬μ μ λ° λ§λ€κΈ°
# μ λ°μ μ μ₯ν λ¬Έμμ΄ μ΄κΈ°ν
half = ""
for char in sorted(counter.keys()): # λ¬Έμλ₯Ό μ¬μ μμΌλ‘ μ λ ¬
half += char * (counter[char] // 2) # ν΄λΉ λ¬Έμμ μ λ° κ°μλ§νΌ μΆκ°
# Step 5: μ€μμ λμ λ¬Έμ κ²°μ
# νμ κ° λ¬Έμκ° μλ€λ©΄ κ·Έ μ€ νλλ₯Ό μ€μμ λμ
middle = odd_chars[0] if odd_chars else ""
# Step 6: ν°λ¦°λ둬 μμ±
# μ λ° + μ€μ λ¬Έμ + μ λ°(μμ)
result = half + middle + half[::-1]
return result
# μ
λ ₯ λ°κΈ°
name = input("μ΄λ¦μ μ
λ ₯νμΈμ: ").strip()
print(make_palindrome(name))
μΌλ¨ λ¬Έμ λ₯Ό μ²μλ³΄κ³ ν λ¦°λλ‘¬μ΄ λμ§ λͺ°λΌμ μ°Ύμλ΄€μ΅λλ€ γ ,,
μ€κ°μ κΈ°μ€μΌλ‘ μμͺ½μ΄ λμΉμ΄μ΄μΌ νκΈ°λλ¬Έμ νμμ μνλ²³μ μ€κ° νλλ§ μμ΄μΌνλ€λκ² ν΅μ¬ λ‘μ§μ΄μμ΅λλ€.
μΉ΄μ΄ν°λ₯Ό μ¬μ©ν΄ μνλ²³λ€μ μλ₯Ό λμ
λ¬λλ‘ μ μ₯ν΄μ£Όκ³ , ODDμ¦ νμλ¬Έμλ₯Ό μ§μ ν΄μ€λλ€.
μ¬κΈ°μ νμκ° νλμ¬μΌλ§ λ§λ€ μ μκ³ μλλ©΄ λ¬Έμμ΄μ μΆλ ₯ν©λλ€.
halfμ μ§μμΈ λ¬Έμμ΄λ€μ μ¬μ μμΌλ‘ μ λ ¬ν΄μ μΆκ°ν΄μ£Όκ³ μ€κ°κΈμλ₯Ό λ£μ λ€ λ°λλ‘ λ€μ μ λ°μ λ£μ΄μ€λλ€.
π λ¬Έμ λ§ν¬
ν¬λ¦¬μ€λ§μ€κ° νλ¬ μ λ λ¨μ μμ μ λ¬μ½€ν λ¬Έμ λ₯Ό μ€λΉνμλλ€ π
ν°λ¦°λ둬 λ§λ€κΈ°
βοΈ μμλ μκ°
30m
β¨ μλ μ½λ
λ¬Έμ μ λμ΄λλ μ΄λ ΅μ§ μμ΅λλ€. μ΄μ μ²λΌ ꡬνμ λΉ λ₯΄κ³ μ ννκ² νκΈ° μν΄ λΉμ·ν λμ΄λμ λ¬Έμ λ₯Ό κ°μ Έμμ΅λλ€.
λ¬Έμ μμ²΄κ° μ΄λ ΅μ§ μμΌλ νλ²μ λ§μΆλ κ²μ μ°μ΅ν΄λ³΄μΈμ..! λλ²κΉ λ μ΅λν λ¦κ² νλ©΄μ λ¨Έλ¦¬λ‘ λ§μ μμΈ μ¬νλ€μ μκ°νλ μ°μ΅μ νκ³ μλλ° κ½€λ μλ―Έμλ κ² κ°μμ.
β μμ΄λμ΄ : μνλ²³μ λ΄λ λ°°μ΄μ λ§λ€κ³ νλμ© κΊΌλ΄μ μ΄λ€
π μλ‘κ² μκ²λ λ΄μ©