Skip to content

Instantly share code, notes, and snippets.

@nak3
Created March 30, 2017 12:00
Show Gist options
  • Save nak3/efb31e53bc07acfdf953964d870db1e8 to your computer and use it in GitHub Desktop.
Save nak3/efb31e53bc07acfdf953964d870db1e8 to your computer and use it in GitHub Desktop.
read one line including spaces and split the words by the spaces
#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