일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 조지아텍
- 매트랩
- 방송통신대학교
- 캐나다 영주권
- 선형대수
- 프로그래머스
- omscs
- 온라인석사
- 머신러닝
- zeros
- 개발자
- MATLAB
- 알고리즘
- leetcode
- 딥러닝
- LAA
- Deep learning
- mpnp
- 주정부이민
- Plotting
- 위니펙
- 방통대
- cpp
- 기본
- EOI
- C++
- 코딩테스트
- 컴퓨터과학과
- machine learning
- LV1
Archives
- Today
- Total
Byte by Byte
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 |