Skip to content

Instantly share code, notes, and snippets.

@palmenros
Created December 12, 2018 22:10
Show Gist options
  • Save palmenros/66db80827a89ac9b3a4dc4bf3e35cd55 to your computer and use it in GitHub Desktop.
Save palmenros/66db80827a89ac9b3a4dc4bf3e35cd55 to your computer and use it in GitHub Desktop.
Amigo Invisible
/**
* Usage: Input a name per line (press enter after input name). When finished inputed names, enter an empty line.
*
*/
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <random>
#include <chrono>
#include <limits>
using namespace std;
void clear()
{
system("cls");
}
int main()
{
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
string line;
vector<string> names;
while(getline(cin, line) && line != "")
{
names.push_back(line);
}
cout << "Participantes: " << endl;
for(unsigned int i = 0; i < names.size(); i++)
{
cout << i + 1 << ") " << names[i] << endl;
}
vector<string> shuffled = names;
shuffle(shuffled.begin(), shuffled.end(), default_random_engine(seed));
/*
cout << endl << "Shuffled: " << endl;
for(unsigned int i = 0; i < shuffled.size(); i++)
{
cout << i + 1 << ") " << shuffled[i] << endl;
}
*/
cin.ignore(numeric_limits<int>::max(), '\n');
cout << endl << "Regalos: " << endl;
for(unsigned int i = 0; i < names.size(); i++)
{
auto pos = find(shuffled.begin(), shuffled.end(), names[i]);
unsigned int index = pos - shuffled.begin();
unsigned int nxt = (index + 1) % shuffled.size();
clear();
cout << names[i] << ", pulsa una tecla. " << endl;
cin.get();
cout << names[i] << ", regalas a " << shuffled[nxt] << "." << endl;
cin.get();
clear();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment