C++)
#include <string>
#include <vector>
using namespace std;
string solution(vector<int> food)
{
int ele = 0;
string front = "";
string back = "";
for(int idx = 1; idx < food.size(); idx++)
{
ele = food.at(idx);
for(int cnt = 0; cnt < ele/2; cnt++)
{
front += to_string(idx);
back = to_string(idx) + back;
}
}
return front+"0"+back;
}
Python)
def solution(food):
answer = ''
for i in range(1, len(food)):
for _ in range(food[i]//2):
answer += str(i)
return answer + '0' + answer[::-1]'프로그래머스 > Level1' 카테고리의 다른 글
| [Level 1] 모의고사 (C++/Python) (0) | 2023.02.07 |
|---|---|
| [Level1] 콜라 문제 (C++/Python) (0) | 2023.02.07 |
| [Level 1] 시저 암호 (C++/Python) (0) | 2021.01.08 |
| [Level 1] 수박수박수박수박수박수? (C++/Python) (0) | 2021.01.08 |
| [Level 1] 문자열을 정수로 바꾸기 (C++/Python) (0) | 2021.01.08 |