Created
March 30, 2017 12:00
-
-
Save nak3/efb31e53bc07acfdf953964d870db1e8 to your computer and use it in GitHub Desktop.
read one line including spaces and split the words by the spaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define INF 2000000000 | |
#define MOD 1000000007 | |
typedef long long ll; | |
typedef pair<int, int> P; | |
int main() | |
{ | |
string s; | |
getline(cin, s); | |
cout << s << "\n"; | |
vector<string> list; | |
stringstream ss(s); | |
string item; | |
while (getline(ss, item, ' ') && !item.empty()) { | |
list.push_back(item); | |
} | |
for (int i = 0; i < list.size(); i++) { | |
cout << list[i] << "\n"; | |
} | |
} | |
/* | |
$ ./a.out | |
a b c | |
a b c | |
a | |
b | |
c | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment