#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(vector<int> food) {
string answer = "0";
string substr;
for(int i = 1; i< food.size(); ++i)
{
int eachfoodNum = food[i] /2;
if(eachfoodNum > 0)
{
substr.append(eachfoodNum, i + '0');
}
}
answer = substr + answer;
reverse(substr.begin(), substr.end());
answer += substr;
return answer;
}
string operator +
_NODISCARD inline basic_string<_Elem, _Traits, _Alloc> operator+(
const basic_string<_Elem, _Traits, _Alloc>& _Left,
_In_z_ const _Elem * const _Right)
{ // return string + NTCTS
using _String_type = basic_string<_Elem, _Traits, _Alloc>;
using _Size_type = typename _String_type::size_type;
_String_type _Ans;
_Ans.reserve(_Convert_size<_Size_type>(_Left.size() + _Traits::length(_Right)));
_Ans += _Left;
_Ans += _Right;
return (_Ans);
}
string append
basic_string& append(_CRT_GUARDOVERFLOW const size_type _Count, const _Elem _Ch)
{ // append _Count * _Ch
auto& _My_data = this->_Get_data();
const size_type _Old_size = _My_data._Mysize;
if (_Count <= _My_data._Myres - _Old_size)
{
_My_data._Mysize = _Old_size + _Count;
_Elem * const _Old_ptr = _My_data._Myptr();
_Traits::assign(_Old_ptr + _Old_size, _Count, _Ch);
_Traits::assign(_Old_ptr[_Old_size + _Count], _Elem());
return (*this);
}
가급적 + 쓰지 말고 append 쓰자!!
'책 > 프로그래머스' 카테고리의 다른 글
| [ 프로그래머스] #131127 할인행사 (0) | 2022.11.27 |
|---|---|
| 프로그래머스 - 타겟 넘버(DFS/BFS) C++ (0) | 2022.11.06 |
| [프로그래머스] 연속 부분 수열 합의 개수 (0) | 2022.11.06 |
| 프로그래머스 햄버거만들기 (아직푸는중) (0) | 2022.11.01 |