fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Player
  6. {
  7. string name;
  8. public:
  9. Player(string name)
  10. {
  11. this->name = name;
  12. }
  13.  
  14. string get_name()
  15. {
  16. return this->name;
  17. }
  18. };
  19.  
  20. bool add_player(vector<Player> &player_vector)
  21. {
  22. string name;
  23. string comp_name;
  24. //getline(cin, name);
  25. //system("CLS");
  26. cout << "Podaj login gracza: ";
  27. getline(cin, name);
  28. for (int i = 0; i < player_vector.size(); i++)
  29. {
  30. comp_name = player_vector[i].get_name();
  31. if (name == comp_name)
  32. {
  33. cout << endl;
  34. cout << "Wybrany login jest zajety.";
  35. cout << flush;
  36. //Sleep(2000);
  37. return false;
  38. }
  39. }
  40. player_vector.push_back(Player(name));
  41. cout << "Gracz " << name << " pomyslnie dodany do ligi.";
  42. //Sleep(2000);
  43. return true;
  44. }
  45.  
  46. int main() {
  47. vector<Player> list;
  48.  
  49. cout << (add_player(list)) ? "TAK" : "NIE";
  50. cout << endl;
  51. cout << (add_player(list)) ? "TAK" : "NIE";
  52. cout << endl;
  53. cout << (add_player(list)) ? "TAK" : "NIE";
  54. cout << endl;
  55. cout << (add_player(list)) ? "TAK" : "NIE";
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 3476KB
stdin
adam
jeden
dwa
jeden
stdout
Podaj login gracza: Gracz adam pomyslnie dodany do ligi.1
Podaj login gracza: Gracz jeden pomyslnie dodany do ligi.1
Podaj login gracza: Gracz dwa pomyslnie dodany do ligi.1
Podaj login gracza: 
Wybrany login jest zajety.0