Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "graph.h"
- #include "hashtable.h"
- #include "hash.h"
- #include <iostream>
- #include <string>
- #include <string.h>
- #include <stdlib.h>
- using namespace std;
- bool is_number(const std::string& s)
- {
- std::string::const_iterator it = s.begin();
- while (it != s.end() && std::isdigit(*it)) ++it;
- return !s.empty() && it == s.end();
- }
- void initialize_sensors(int nrsens, Graph& sensors_distance)
- {
- int sensors, i, j;
- for(i = 0; i < nrsens; ++i)
- {
- for(j = 0; j < nrsens; ++j)
- {
- cin >> sensors;
- if(i != j)
- {
- sensors_distance.add_to_edge(i,j, sensors);
- }
- }
- }
- }
- void initialize_team(int no1, int no2, Hashtable<string, int>& players)
- {
- int i;
- string name;
- for(i = 0; i < no1; ++i)
- {
- cin >> name;
- players.entry(name, i, 0);
- }
- for(i = 0; i < no2; ++i)
- {
- cin >> name;
- players.entry(name, i + no1, 1);
- }
- }
- void read(int&win0, int& win1, Graph& sensors_distance, Graph& unique_sensors, Graph& shooting, Hashtable<string, int>& players)
- {
- string joc_tag, s1, s2, s3;
- int nrjocuri = 2;
- float w_c0, w_c1;
- cin >> joc_tag;
- while(1)
- {
- cin >> s1;
- if(s1.find("END_CHAMPIONSHIP") != string::npos)
- {
- w_c0 = players.is_alive(0)*(players.total_score(0)/players.max_score())*(players.total_distance(0)/players.max_distance());
- w_c1 = players.is_alive(1)*(players.total_score(1)/players.max_score())*(players.total_distance(1)/players.max_distance());
- }
- if (s1.find("JOC_") != string::npos)
- {
- players.new_game();
- unique_sensors.reinitialize();
- if(players.is_alive(0) != 0)
- {
- ++win0;
- }
- else
- {
- ++win1;
- }
- }
- else
- {
- if(is_number(s1))
- {
- cin >> s2;
- }
- }
- }
- }
- int main()
- {
- int nrsens, no1, no2;
- int win0 = 0, win1 = 0;
- cin >> nrsens;
- Graph sensors_distance(nrsens, nrsens);
- initialize_sensors(nrsens, sensors_distance);
- cin >> no1 >> no2;
- Graph unique_sensors(no1+no2, nrsens);
- Graph shooting(no1+no2, no1+no2);
- Hashtable<string, int> players(no1+no2, hash);
- initialize_team(no1, no2, players);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement