-
[programmers] 이상한 문자 만들기 / C++공부/PS (programmers) 2022. 7. 20. 23:18
https://school.programmers.co.kr/learn/courses/30/lessons/12930?language=cpp
#include <string> #include <vector> #include <iostream> using namespace std; string solution(string s) { string answer = ""; string tmp = ""; string space_delimiter = " "; vector <string> vec; size_t pos = 0; while ((pos = s.find(space_delimiter)) != string::npos) { vec.push_back(s.substr(0, pos)); s.erase(0, pos + space_delimiter.length()); } vec.push_back(s); // 마지막 원소 for(int i=0; i<vec.size(); i++) { for(int j=0; j < vec[i].size(); j++) { if(j%2 == 0) answer += toupper(vec[i][j]); else answer += tolower(vec[i][j]); } answer += " "; } return answer.substr(0, answer.length()-1); }
✍ 구분자로 문자열 자르기
✍ C++ 문자열을 대/소문자로 변환하기
'공부 > PS (programmers)' 카테고리의 다른 글
[programmers] 폰켓몬 / C++ (0) 2022.07.27 [programmers] 제일 작은 수 제거하기 / C++ (0) 2022.07.19 [programmers] 소수 만들기 / C++ (0) 2022.07.19 [programmers] 두 개 뽑아서 더하기 / C++ (0) 2022.07.19 [programmers] 프린터 / C++ (0) 2022.05.18