일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 기본
- 딥러닝
- 컴퓨터과학과
- 주정부이민
- cpp
- Plotting
- leetcode
- EOI
- omscs
- Deep learning
- C++
- 캐나다 영주권
- LV1
- 프로그래머스
- 방통대
- 조지아텍
- zeros
- 마니토바
- MATLAB
- mpnp
- 방송통신대학교
- 머신러닝
- 선형대수
- LAA
- 개발자
- 매트랩
- 알고리즘
- machine learning
- 온라인석사
- 코딩테스트
Archives
- Today
- Total
Krononberg
leetcode 1859. Sorting the Sentence.cpp 본문
class Solution {
public:
string sortSentence(string s) {
//sentence를 word로 쪼개어 vector<string>으로 저장
vector<string>tempVec;
for (int i = 0; i < s.size();) {
string tempStr = "";
int i2 = i;
for (int j = i; s[j] != 32 && j < s.size(); j++)
{
tempStr += s[j];
i2 = j + 2;
}
i = i2;
tempVec.push_back(tempStr);
if (i2 > s.size())
break;
}
//쪼갠 word를 word옆 숫자의 순서대로 res(string)에 삽입
string res = "";
int k = '1';
while (1) {
for (int i = 0; i < tempVec.size(); i++) {
string tempStr2 = "";
for (int j = 0; j < tempVec[i].size(); j++) {
tempStr2 += tempVec[i][j];
if (tempVec[i][j] == k)
{
tempStr2.erase(j);
res += tempStr2;
res += " ";
}
}
}
k++;
if ((k - 49) == tempVec.size())
{
res.erase(res.size()-1);
return res;
}
}
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
프로그래머스 - 직업군 추천하기 C++ (0) | 2021.08.23 |
---|---|
크레인 인형뽑기 c++풀이 (0) | 2021.08.23 |
프로그래머스 lv2 테스트 2번 :카펫 c++ 풀이 (0) | 2021.06.14 |
프로그래머스 lv2 테스트 :숫자의 표현 c++ 풀이 (0) | 2021.06.14 |
[프로그래머스/Level2] 기능개발 C++ 소스 (0) | 2021.01.04 |