https://school.programmers.co.kr/learn/courses/30/lessons/134240
준비한 음식의 갯수를 2로 나눈 몫을 answer에 char로 더해주고 0을 한번 더해준 뒤 answer을 reverse한 str을 answer에 더해준다.
#include <string>
#include <vector>
using namespace std;
string solution(vector<int> food) {
string answer = "";
for(int i = 1; i < food.size(); i++)
{
for(int j = 0; j < food[i]/2; j++)
{
answer += ('0' + i);
}
}
string str(answer.rbegin(),answer.rend());
answer += "0";
answer += str;
return answer;
}
#include <string>
#include <vector>
using namespace std;
string solution(vector<int> food) {
string answer = "0";
int check;
for(int i=food.size()-1; i>0; i--){
check = food[i]/2;
while(check){
answer = to_string(i) + answer + to_string(i);
check--;
}
}
return answer;
}
똑같은 풀이도 있었고 다른풀이를 가져왔다.
똑같이 2를 나눠서 앞과 뒤에 더해간다.