-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_number_only.cpp
More file actions
51 lines (37 loc) · 905 Bytes
/
filter_number_only.cpp
File metadata and controls
51 lines (37 loc) · 905 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
using namespace std;
vector<string> split(const string &s, char delimiter) {
vector<string> tokens;
string token;
istringstream tokenStream(s);
while (getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}
vector<string> filter(vector<string> v) {
vector<string> new_v;
for (string word : v) {
if (atoi(word.c_str()) != 0) {
new_v.push_back(word);
}
}
return new_v;
}
int main() {
// char str[80] = "1 abc 25 kim 0 34 11";
char str[80];
cin.getline(str, 80);
string s = string(str);
auto split_string = split(s, ' ');
auto onli_int = filter(split_string);
stringstream n;
for (auto wint :onli_int) {
n << wint << ' ';
}
cout << n.str() << endl;
return 0;
}