Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
7.1 kB
28
Indexable
Never
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct team {
public:
	string name;
	int count_play;
	int count_nohome_play;
	int win;
	int count_goal;
	team(string name, int count_play, int count_nohome_play, int win, int count_goal) : name(name), count_play(count_play), count_nohome_play(count_nohome_play), win(win), count_goal(count_goal) {};
};
int main() {
	vector <team> team_opponent;
	for (int i = 0; i < 10; i++) {
		team_opponent.push_back(team("team_nick", 0, 0, 0, 0));
	}
	vector <string> games;
	vector <string> team_record;
	vector <int> k;
	vector <int> ki;
	for (int f = 0; f < 4; f++){
			k.push_back(f);
			ki.push_back(f);
	}
	int m = 0;
	bool EST = false;
	string str;
	string temp;
	ifstream fin("input.txt");
	while (getline(fin, str)){
		games.push_back(str);
	}
	fin.close();
	ofstream fout("output.txt");
	for (int i = 0; i < games.size(); i++) {
		for (int Y = 0; Y < games[i].length(); Y++) {
			if (games[i][Y] == ' ') {
				ki[m] = Y;
				m += 1;
			}
			if (games[i][Y] == ':') {
				ki[3] = Y;
			}
		}
		m = 0;
		str = games[i].substr(0, ki[0]);
		if (!(find(team_record.begin(), team_record.end(), str) != team_record.end())) {
			team_record.push_back(str);
			for (int j = 0; j < games.size(); j++)
			{
				for (int Y = 0; Y < games[j].length(); Y++) {
					if (games[j][Y] == ' ') {
						k[m] = Y;
						m += 1;
					}
					if (games[j][Y] == ':') {
						k[3] = Y;
					}
				}
				m = 0;
				temp = games[j].substr(k[1]+1, k[2] - k[1]-1);
				if (str == games[j].substr(0, k[0])) {
					for (int f = 0; f < team_opponent.size(); f++) {
						if (temp == team_opponent[f].name) {
							EST = true;
							break;
						}
					}
					if (!EST) {
						for (int d = 0; d < team_opponent.size(); d++) {
							if (team_opponent[d].name == "team_nick") {
								team_opponent[d].name = temp;
								break;
							}
						}
					}
					EST = false;
					for (int T = 0; T < team_opponent.size(); T++) {
						if (team_opponent[T].name == temp ) {
							team_opponent[T].count_play += 1;
							team_opponent[T].count_nohome_play += 0;
							team_opponent[T].win += stoi(games[j].substr(k[2]+1, k[3] - k[2]-1)) > stoi(games[j].substr(k[3]+1, games[j].length() - k[3]-1)) ? 1: 0;
							team_opponent[T].count_goal += stoi(games[j].substr(k[2]+1, k[3] - k[2]-1));
							break;
						}
					}

				}
				temp = games[j].substr(0, k[0]);
				if (str == games[j].substr(k[1] + 1, k[2] - k[1] - 1)) {
					for (int f = 0; f < team_opponent.size(); f++) {
						if (temp == team_opponent[f].name) {
							EST = true;
							break;
						}
					}
					if (!EST) {
						for (int d = 0; d < team_opponent.size(); d++) {
							if (team_opponent[d].name == "team_nick") {
								team_opponent[d].name = temp;
								break;
							}
						}
					}
					EST = false;
					for (int T = 0; T < team_opponent.size(); T++) {
						if (team_opponent[T].name == temp) {
							team_opponent[T].count_play += 1;
							team_opponent[T].count_nohome_play += 1;
							team_opponent[T].win += stoi(games[j].substr(k[2]+1, k[3] - k[2]-1)) < stoi(games[j].substr(k[3]+1, games[j].length() - k[3]-1)) ? 1 : 0;
							team_opponent[T].count_goal += stoi(games[j].substr(k[3]+1, games[j].length() - k[3]-1));
							break;
						}
					}

				}

			}
			for (int f = 3; f >= 0; f--) {
				k[f] = 0;
			}
			fout << str << "\n";
			for (int U = 0; U < team_opponent.size(); U++) {
				if (team_opponent[U].name != "team_nick") {
					fout << team_opponent[U].name << " " << team_opponent[U].count_play << " " << team_opponent[U].count_nohome_play << " " << team_opponent[U].win << " " << team_opponent[U].count_goal << "\n";
				}
			}
			for (int T = 0; T < team_opponent.size(); T++) {
				team_opponent[T].name = "team_nick";
				team_opponent[T].count_play = 0;
				team_opponent[T].count_nohome_play = 0;
				team_opponent[T].win = 0 ;
				team_opponent[T].count_goal = 0;
			}
		}




		str = games[i].substr(ki[1] + 1, ki[2] - ki[1] - 1);
		if (!(find(team_record.begin(), team_record.end(), str) != team_record.end())) {
			team_record.push_back(str);
			for (int j = 0; j < games.size(); j++)
			{
				for (int Y = 0; Y < games[j].length(); Y++) {
					if (games[j][Y] == ' ') {
						k[m] = Y;
						m += 1;
					}
					if (games[j][Y] == ':') {
						k[3] = Y;
					}
				}
				m = 0;
				temp = games[j].substr(k[1] + 1, k[2] - k[1] - 1);
				if (str == games[j].substr(0, k[0])) {
					for (int f = 0; f < team_opponent.size(); f++) {
						if (temp == team_opponent[f].name) {
							EST = true;
							break;
						}
					}
					if (!EST) {
						for (int d = 0; d < team_opponent.size(); d++) {
							if (team_opponent[d].name == "team_nick") {
								team_opponent[d].name = temp;
								break;
							}
						}
					}
					EST = false;
					for (int T = 0; T < team_opponent.size(); T++) {
						if (team_opponent[T].name == temp) {
							team_opponent[T].count_play += 1;
							team_opponent[T].count_nohome_play += 0;
							team_opponent[T].win += stoi(games[j].substr(k[2] + 1, k[3] - k[2] - 1)) > stoi(games[j].substr(k[3] + 1, games[j].length() - k[3] - 1)) ? 1 : 0;
							team_opponent[T].count_goal += stoi(games[j].substr(k[2] + 1, k[3] - k[2] - 1));
							break;
						}
					}

				}
				temp = games[j].substr(0, k[0]);
				if (str == games[j].substr(k[1] + 1, k[2] - k[1] - 1)) {
					for (int f = 0; f < team_opponent.size(); f++) {
						if (temp == team_opponent[f].name) {
							EST = true;
							break;
						}
					}
					if (!EST) {
						for (int d = 0; d < team_opponent.size(); d++) {
							if (team_opponent[d].name == "team_nick") {
								team_opponent[d].name = temp;
								break;
							}
						}
					}
					EST = false;
					for (int T = 0; T < team_opponent.size(); T++) {
						if (team_opponent[T].name == temp) {
							team_opponent[T].count_play += 1;
							team_opponent[T].count_nohome_play += 1;
							team_opponent[T].win += stoi(games[j].substr(k[2] + 1, k[3] - k[2] - 1)) < stoi(games[j].substr(k[3] + 1, games[j].length() - k[3] - 1)) ? 1 : 0;
							team_opponent[T].count_goal += stoi(games[j].substr(k[3] + 1, games[j].length() - k[3] - 1));
							break;
						}
					}

				}

			}
			for (int f = 3; f >= 0; f--) {
				k[f] = 0;
			}
			fout << str << "\n";
			for (int U = 0; U < team_opponent.size(); U++) {
				if (team_opponent[U].name != "team_nick") {
					fout << team_opponent[U].name << " " << team_opponent[U].count_play << " " << team_opponent[U].count_nohome_play << " " << team_opponent[U].win << " " << team_opponent[U].count_goal << "\n";
				}
			}
			for (int T = 0; T < team_opponent.size(); T++) {
				team_opponent[T].name = "team_nick";
				team_opponent[T].count_play = 0;
				team_opponent[T].count_nohome_play = 0;
				team_opponent[T].win = 0;
				team_opponent[T].count_goal = 0;
			}
		}
	}
	fout.close();
}