일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 방송통신대학교
- 머신러닝
- LAA
- 알고리즘
- EOI
- mpnp
- 기본
- 온라인석사
- 캐나다 영주권
- machine learning
- omscs
- 주정부이민
- 프로그래머스
- 조지아텍
- 매트랩
- cpp
- 선형대수
- C++
- 컴퓨터과학과
- zeros
- 개발자
- MATLAB
- 방통대
- leetcode
- Plotting
- 마니토바
- Deep learning
- 코딩테스트
- 딥러닝
- LV1
Archives
- Today
- Total
Krononberg
1694. Reformat Phone Number.cpp 본문
class Solution {
public:
string reformatNumber(string number) {
if(number.size()<3)return number;
string nb ="";
for(auto n : number) if(isdigit(n)) nb+=n;
string res="";
int x = nb.size()%3;
if(x==1){
for(int i =0; i<nb.size();i++){
res+=nb[i];
if(i==nb.size()-3) {
res+='-';
res+=nb[++i];
res+=nb[++i];
return res;
}
if(i%3 ==2) res+='-';
}
}
for(int i =0; i<nb.size();i++){
res+=nb[i];
if(i!= nb.size()-1 && i%3 ==2) res+='-';
}
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1078. Occurrences After Bigram.cpp (0) | 2021.12.15 |
---|---|
1598. Crawler Log Folder.cpp (0) | 2021.12.15 |
575. Distribute Candies.cpp (0) | 2021.12.15 |
884. Uncommon Words from Two Sentences.cpp (0) | 2021.12.15 |
46. Permutations.cpp (0) | 2021.12.14 |