PCLP2/lab05/tema.cpp
Fándly Gergő 7adb051d16 chore: Lab06
2020-04-12 12:02:41 +03:00

52 lines
913 B
C++

#include <iostream>
#include <string>
#include <list>
#include <sstream>
#include <algorithm>
using namespace std;
void insertToPlace(list<string>* v, const string* word){
if(!v->size() || *word < v->front()){
v->push_front(*word);
return;
}
if(*word == v->front()){
return;
}
for(list<string>::iterator it = next(v->begin()); it != v->end(); it++){
if(*word == *it){
return;
}
if(*word > *prev(it) && *word < *it){
v->insert(it, *word);
return;
}
}
v->push_back(*word);
}
int main(){
ios::sync_with_stdio(false);
cout<<"Introduce a line: ";
string line;
getline(cin, line);
list<string> v;
istringstream sstream(line);
string word;
while(getline(sstream, word, ' ')){
insertToPlace(&v, &word);
}
cout<<"Distinct words ordered alphabetically:\n";
for(list<string>::iterator it = v.begin(); it != v.end(); it++){
cout<<*it<<"\n";
}
cout.flush();
return 0;
}