Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include "graph.h"
  2. #include "hashtable.h"
  3. #include "hash.h"
  4. #include <iostream>
  5. #include <string>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. using namespace std;
  10.  
  11. bool is_number(const std::string& s)
  12. {
  13. std::string::const_iterator it = s.begin();
  14. while (it != s.end() && std::isdigit(*it)) ++it;
  15. return !s.empty() && it == s.end();
  16. }
  17.  
  18. void initialize_sensors(int nrsens, Graph& sensors_distance)
  19. {
  20. int sensors, i, j;
  21.  
  22. for(i = 0; i < nrsens; ++i)
  23. {
  24. for(j = 0; j < nrsens; ++j)
  25. {
  26. cin >> sensors;
  27. if(i != j)
  28. {
  29. sensors_distance.add_to_edge(i,j, sensors);
  30. }
  31. }
  32. }
  33.  
  34. }
  35.  
  36. void initialize_team(int no1, int no2, Hashtable<string, int>& players)
  37. {
  38. int i;
  39. string name;
  40.  
  41. for(i = 0; i < no1; ++i)
  42. {
  43. cin >> name;
  44.  
  45. players.entry(name, i, 0);
  46. }
  47. for(i = 0; i < no2; ++i)
  48. {
  49. cin >> name;
  50.  
  51. players.entry(name, i + no1, 1);
  52. }
  53. }
  54.  
  55. void read(int&win0, int& win1, Graph& sensors_distance, Graph& unique_sensors, Graph& shooting, Hashtable<string, int>& players)
  56. {
  57. string joc_tag, s1, s2, s3;
  58. int nrjocuri = 2;
  59. float w_c0, w_c1;
  60. cin >> joc_tag;
  61.  
  62. while(1)
  63. {
  64. cin >> s1;
  65.  
  66. if(s1.find("END_CHAMPIONSHIP") != string::npos)
  67. {
  68.  
  69. w_c0 = players.is_alive(0)*(players.total_score(0)/players.max_score())*(players.total_distance(0)/players.max_distance());
  70. w_c1 = players.is_alive(1)*(players.total_score(1)/players.max_score())*(players.total_distance(1)/players.max_distance());
  71.  
  72.  
  73. }
  74. if (s1.find("JOC_") != string::npos)
  75. {
  76. players.new_game();
  77. unique_sensors.reinitialize();
  78.  
  79. if(players.is_alive(0) != 0)
  80. {
  81. ++win0;
  82. }
  83. else
  84. {
  85. ++win1;
  86. }
  87. }
  88. else
  89. {
  90. if(is_number(s1))
  91. {
  92. cin >> s2;
  93. }
  94. }
  95.  
  96. }
  97. }
  98. int main()
  99. {
  100. int nrsens, no1, no2;
  101. int win0 = 0, win1 = 0;
  102.  
  103. cin >> nrsens;
  104.  
  105. Graph sensors_distance(nrsens, nrsens);
  106.  
  107. initialize_sensors(nrsens, sensors_distance);
  108.  
  109. cin >> no1 >> no2;
  110.  
  111. Graph unique_sensors(no1+no2, nrsens);
  112.  
  113. Graph shooting(no1+no2, no1+no2);
  114.  
  115. Hashtable<string, int> players(no1+no2, hash);
  116.  
  117. initialize_team(no1, no2, players);
  118.  
  119.  
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement