Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. //VisualStudio compatibility
  6. #ifdef _MSC_VER
  7. #define _CRT_SECURE_NO_DEPRECATE
  8. #pragma warning (disable : 4996)
  9. #endif
  10. //
  11.  
  12. struct ship {
  13. char shipname[15];
  14. int maxSpace;
  15. };
  16.  
  17. struct person {
  18. int number;
  19. ship* team;
  20. };
  21.  
  22. ship* FindShip(person* osobyTab, int liczbaOsob, char szukanaDruzyna[25])
  23. {
  24. for (int i = 0; i < liczbaOsob; i++)
  25. {
  26. for (int j = 0; j < 25; j++)
  27. {
  28. if (osobyTab[i].team->shipname[j] != szukanaDruzyna[j])
  29. break;
  30. if (szukanaDruzyna[j] == '\0' && osobyTab[i].team->shipname[j] == '\0')
  31. return osobyTab[i].team;
  32. }
  33. }
  34. }
  35.  
  36. bool TeamExist(person* osobyTab, int liczbaOsob, char szukanaDruzyna[25])
  37. {
  38. for (int i = 0; i < liczbaOsob; i++)
  39. {
  40. if (osobyTab[i].team != nullptr)
  41. {
  42. for (int j = 0; j < 25; j++)
  43. {
  44. if (osobyTab[i].team->shipname[j] != szukanaDruzyna[j])
  45. break;
  46. if (szukanaDruzyna[j] == '\0' && osobyTab[i].team->shipname[j] == '\0')
  47. return true;
  48. }
  49. }
  50. }
  51. return false;
  52. }
  53.  
  54. int main() {
  55.  
  56. int liczbaOsob;
  57. cin >> liczbaOsob;
  58. person* osobyTab = new person[liczbaOsob];
  59.  
  60. ship* currentShip= NULL;
  61.  
  62. for (int j = 0; j < liczbaOsob; j++)
  63. {
  64. osobyTab[j].number = j;
  65. osobyTab[j].team = NULL;
  66. }
  67. char key = ' ';
  68.  
  69. int peopleInCurrentTeam = 0;
  70.  
  71. while (key != 'Q')
  72. {
  73. cin >> key;
  74.  
  75. if (key == 'A')
  76. {
  77. char nazwaDruzyny[15];
  78. cin >> nazwaDruzyny;
  79.  
  80. if (TeamExist(osobyTab, liczbaOsob, nazwaDruzyny))
  81. {
  82. currentShip = FindShip(osobyTab, liczbaOsob, nazwaDruzyny);
  83. }
  84. else
  85. {
  86. if (currentShip == NULL)
  87. {
  88. currentShip = new ship;
  89. for (int i = 0; i < 25; i++)
  90. {
  91. currentShip->shipname[i] = nazwaDruzyny[i];
  92. }
  93. currentShip->teamSize = 0;
  94. }
  95. else
  96. {
  97. if (currentShip->teamSize == 0)
  98. delete currentShip;
  99.  
  100. currentShip = new ship;
  101. for (int i = 0; i < 25; i++)
  102. {
  103. currentShip->shipname[i] = nazwaDruzyny[i];
  104. }
  105. currentShip->teamSize = 0;
  106. }
  107. }
  108. }
  109. else if (key == 'B')
  110. {
  111. int indeksOsoby;
  112. cin >> indeksOsoby;
  113. osobyTab[indeksOsoby].team = currentShip;
  114. currentShip->teamSize++;
  115. }
  116. else if (key == 'C')
  117. {
  118. for (int i = 0; i < liczbaOsob; i++)
  119. {
  120. cout << "Osoba " << i << " o numerze " << osobyTab[i].number;
  121. if (osobyTab[i].team == NULL)
  122. {
  123. cout << " osoba nie jest przypisana do zadnej druzyny" << endl;
  124. }
  125. else
  126. {
  127. cout << " druzyna: " << osobyTab[i].team->shipname << " osob w druzynie: " << osobyTab[i].team->teamSize << endl;
  128. }
  129. }
  130. }
  131. }
  132. return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement