accumulate
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
#include <string>
#include <vector>
#include <numeric>
using namespace std;
int solution(vector<int> arr1, vector<int> arr2)
{
if (arr1.size() != arr2.size())
{
return arr1.size() > arr2.size() ? 1 : -1;
}
// begin에서 end까지 합
int sum1 = accumulate(arr1.begin(), arr1.end(), 0);
int sum2 = accumulate(arr2.begin(), arr2.end(), 0);
return sum1 > sum2 ? 1 : sum1 == sum2 ? 0 : -1;
}
insert
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> arr)
{
vector<int> answer;
for (const int& num : arr)
{
// end위치에 num을 num번 추가
answer.insert(answer.end(), num, num);
}
return answer;
}
regex_replace
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
#include <string>
#include <vector>
#include <regex>
using namespace std;
string solution(string rny_string)
{
// rny_string의 "m"을 "rn"으로 교체
string answer = regex_replace(rny_string, regex("m"), "rn");
return answer;
}
'기타' 카테고리의 다른 글
[2024.11.10] (0) | 2024.11.10 |
---|---|
vsseting (0) | 2024.01.22 |