forked from adarshpandey10t/Hacktoberfestmine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringStream.cpp
More file actions
35 lines (30 loc) · 718 Bytes
/
StringStream.cpp
File metadata and controls
35 lines (30 loc) · 718 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
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;
/*
Contributor: Ankit
Problem Statement: https://www.hackerrank.com/challenges/c-tutorial-stringstream/problem
Happy Coding!!!!!
*/
vector<int> parseInts(string str) {
// Complete this function
vector<int> arr;
stringstream ss(str);
int a;
char ch;
while(ss){
if(ss>>a) arr.push_back(a); // Extrracting the numbers nand commas(char) from string(str variable)
ss>>ch;
}
return arr;
}
int main() {
string str;
cin >> str;
vector<int> integers = parseInts(str);
for(int i = 0; i < integers.size(); i++) {
cout << integers[i] << "\n";
}
return 0;
}