Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 백준 17471
- 자료구조
- 5397
- 1764
- 시간 복잡도
- 원판 돌리기
- 스택의 특징
- 백준 1406
- 풀이
- 백준 5397
- 백준 17822
- 해시구현
- 백준 2447
- heap
- Stack 이란
- ㅣ풀이
- 게리멘더링2
- c#
- 별 찍기 10
- 버킷 정렬
- 구현
- 백준 1158
- AVL 시간 복잡도
- 조세퍼스 순열
- 백준 17779
- 백준
- C/C++ 구현
- qorwns
- dfs
- 해시 구현
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 2870] 수학숙제 본문
요구사항
문자열 안에서 숫자를 뽑아내어 오름차순으로 정열하여라
풀이
stoi를 이용한다면 문자열 길이가 100이라면 어마어마하게 큰 숫자이기 때문에 안된다
단어 중간중간을 string으로 뽑아내어 조건에 따라 예외처리 해주고
string을 정렬하여야 한다
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
int n;
int map[51];
int target;
bool com(string a, string b) {
if (a.size() < b.size())
return true;
else if (a.size() == b.size()) {
if (a < b) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
vector<string> v;
for (int i = 0; i < n; i++) {
string str;
string str1;
int flag = 0;
cin >> str;
for (int j = 0; j < str.size(); j++) {
char ch = str[j];
if (((int)ch >= 48) && ((int)ch <= 57)) {
str1 += ch;
}
else {
if (str1.size() > 0) {
v.push_back(str1);
}
str1.clear();
}
}
v.push_back(str1);
}
vector<string> ans;
for (int i = 0; i < v.size(); i++) {
int flag = 0;
string ansstr;
if (v[i] == "") continue;
for (int j = 0; j < v[i].size(); j++) {
if (flag == 0) {
if (v[i][j] == '0') {
continue;
continue;
}
else {
flag = 1;
ansstr += v[i][j];
}
}
else {
ansstr += v[i][j];
}
}
if (flag == 0) {
if (ansstr.size() == 0) {
char ch = '0';
ansstr += ch;
ans.push_back(ansstr);
continue;
}
}
ans.push_back(ansstr);
}
sort(ans.begin(), ans.end(), com);
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
cout << endl;
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 6497] 전력난 (0) | 2020.03.23 |
---|---|
[백준 1924] 2007년 (0) | 2020.03.20 |
[백준 1059] 수2 (0) | 2020.03.20 |
[백준 2839] 설탕 배달 (0) | 2020.03.20 |
[백준 10871] X보다 작은 수 (0) | 2020.03.19 |
Comments