fork download
  1. #include <algorithm>
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <string>
  6. #include <utility>
  7. #include <vector>
  8.  
  9. using namespace std;
  10.  
  11. typedef pair<vector<string>, vector<double>> TransactionList;
  12.  
  13. template <typename T>
  14. TransactionList getTransactionsForSearchCriteria(TransactionList result, T criteria) {
  15. auto& attribute = get<vector<T>>(result);
  16. auto it = lower_bound(attribute.begin(), attribute.end(), criteria);
  17.  
  18. //check that criteria matches transaction attribute
  19. if(it != attribute.end() && *it == criteria) {
  20. cout << criteria << " is a duplicate\n";
  21. }
  22. attribute.insert(it, criteria);
  23. return result;
  24. }
  25.  
  26. int main() {
  27. TransactionList result;
  28. size_t size;
  29. double num;
  30. string i;
  31.  
  32. while(cin >> i) {
  33. if(sscanf(i.c_str(), "%lf%n", &num, &size) == 1 && size == i.size()) {
  34. result = getTransactionsForSearchCriteria(result, num);
  35. } else {
  36. result = getTransactionsForSearchCriteria(result, i);
  37. }
  38. }
  39.  
  40. cout << "Strings:\n\t";
  41. copy(result.first.cbegin(), result.first.cend(), ostream_iterator<string>(cout, " "));
  42. cout << "\nDoubles:\n\t";
  43. copy(result.second.cbegin(), result.second.cend(), ostream_iterator<double>(cout, " "));
  44. }
Success #stdin #stdout 0s 3472KB
stdin
1 Jonathan 2 Mee 3 Jon 4 Mee 1 Lorem 1 Ipsum
stdout
Mee is a duplicate
1 is a duplicate
1 is a duplicate
Strings:
	Ipsum Jon Jonathan Lorem Mee Mee 
Doubles:
	1 1 1 2 3 4