100 lines
1.8 KiB
C++
100 lines
1.8 KiB
C++
#include <iostream>
|
|
#include <list>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <iomanip>
|
|
|
|
using string = std::string;
|
|
|
|
//Place in header!
|
|
template <typename T>
|
|
void printm(T m){
|
|
std::cout << m;
|
|
}
|
|
|
|
template <typename T>
|
|
void printlm(T m){
|
|
printm(m);
|
|
printm("\n");
|
|
}
|
|
|
|
int prompti(string,bool*);
|
|
double promptd(string,bool*);
|
|
string prompts(string,bool*);
|
|
double avg(std::list<double>*);
|
|
void remdups(std::list<string>&);
|
|
|
|
int main() {
|
|
printlm("Remove duplicates for input:");
|
|
bool s {};
|
|
std::list<string> lst {};
|
|
do {
|
|
auto v = prompts("", &s);
|
|
if (s) lst.push_back(v);
|
|
} while (s);
|
|
printlm("Current data:");
|
|
for (const auto c : lst) printlm(c);
|
|
printlm("With Duplicates removed:");
|
|
remdups(lst);
|
|
for (const auto c : lst) printlm(c);
|
|
return 0;
|
|
}
|
|
|
|
int prompti(string message, bool *status) {
|
|
int tr {};
|
|
*status = false;
|
|
std::cout << message;
|
|
if (!(std::cin >> tr)){
|
|
std::cin.clear();
|
|
std::cin.ignore();
|
|
return 0;
|
|
}
|
|
*status = true;
|
|
return tr;
|
|
}
|
|
|
|
double promptd(string message, bool *status) {
|
|
double tr {};
|
|
*status = false;
|
|
std::cout << message;
|
|
if (!(std::cin >> tr)){
|
|
std::cin.clear();
|
|
std::cin.ignore();
|
|
return 0.0;
|
|
}
|
|
*status = true;
|
|
return tr;
|
|
}
|
|
|
|
string prompts(string message, bool *status) {
|
|
string tr {""};
|
|
*status = false;
|
|
std::cout << message;
|
|
if (!(std::cin >> tr)){
|
|
std::cin.clear();
|
|
std::cin.ignore();
|
|
return "";
|
|
}
|
|
*status = true;
|
|
return tr;
|
|
}
|
|
|
|
double avg(std::list<double> *values) {
|
|
double sum {};
|
|
for (const auto c : *values) sum += c;
|
|
return sum / values->size();
|
|
}
|
|
|
|
void remdups(std::list<string> &values) {
|
|
std::map<string,bool> has {};
|
|
auto itr {values.cbegin()};
|
|
while (itr != values.cend()) {
|
|
if (has[*itr]) {
|
|
itr = values.erase(itr);
|
|
} else {
|
|
has[*itr] = true;
|
|
++itr;
|
|
}
|
|
}
|
|
}
|