chore: Lab06
This commit is contained in:
51
lab05/tema.cpp
Normal file
51
lab05/tema.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user