/*
NUR ALEEYA SYAKILA BINTI MUHAMAD SUBIAN A19EC0127 000726100810
NUR HADIRAH MUNAWARAH BINTI ROZMIZAN A19EC0201 000526060076
*/
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#define r 12
#define c 7
#define s 5

void displayLine()
{

	int i;
	do{
		for(int i=0;i<52;i++)
		cout << "-";
	}while (i==52);	
	
}

int findIndWinner(int m[][7], int t[],int highI[])
{
	int highT;
	int highest=-99999999;
	for (int i=0;i<12;i++)
	{
		if(t[i]>highest)
		{
			highest=t[i];
			highI[0] = m[i][1];
			highI[1]=m[i][0];

		}
	}

}
int findTeamWinner(int totG[],int m[][7],int highT[])
{
	int highTeam,highestTeam;
	int highest=totG[0]; 
	for (int i=0;i<3;i++)
	{
		if(totG[i]>highest)
		{
			highestTeam=totG[i];
			highTeam =i+1;
			highT[0]=highTeam;
			highT[1]=highestTeam;
		
		}
	}	
}



int main()
{
	int marks[12][7];
	ifstream inp;
	int toteach[12];
	int totGroup[3];
	
	inp.open("input2.txt");

	if(!inp) 
	{
		cout<<"Sorry, input file does not exist!"<<endl
			<<"Press any key to continue . . .";
		exit(0);
	}
	for (int i=0; i<r; i++)
	{
		for (int j=0;j<c;j++)
		{
			inp>>marks[i][j];
		}
	}

//team1
int suma=0;
	for (int i=0;i<4;i++)
	{
		int sum1=0;
		for (int j=2;j<7;j++)
		{
				sum1+=marks[i][j];
				toteach[i]=sum1;
				
		}
		suma+=sum1;
	}
totGroup[0]=suma;
		
		
//team2	
int sumb=0;
	for (int i=4;i<8;i++)
	{
		int sum2=0;
		for (int j=2;j<7;j++)
		{
			sum2+=marks[i][j];
			toteach[i]=sum2;
		}
		sumb+=sum2;
	}
totGroup[1]=sumb;
		
//team3		
int sumc=0;
	for (int i=8;i<12;i++)
	{
		int sum3=0;
		for (int j=2;j<7;j++)
		{
				sum3+=marks[i][j];
				toteach[i]=sum3;
		}
		sumc+=sum3;
	}
totGroup[2]=sumc;
	
//output	
displayLine();
cout <<endl;
	cout<<"Id"<<setw(7)<<"E1"<<setw(8)<<"E2"<<setw(8)<<"E3"<<setw(8)<<"E4"<<setw(8)<<"E5"<<setw(11)<<"Total"<<endl;
	
displayLine();
cout <<endl;


cout <<"TEAM "<<marks[0][0]<<endl;
	for (int i=0; i<4; i++)
	{
		for (int j=1; j<7; j++)
		{
			cout<<marks[i][j]<<"\t";
			
		}
		cout<<toteach[i];
		cout<<endl;
	}
	cout << "TOTAL"<<setw(46);
	cout << totGroup[0]<<endl;
	
	
displayLine();
cout <<endl;


cout <<"TEAM "<<marks[5][0]<<endl;
	
	for (int i=4; i<8; i++)
	{
		for (int j=1; j<7; j++)
		{
			cout<<marks[i][j] <<"\t";
		}
		cout<<toteach[i];
		cout<<endl;
	}
	cout << "TOTAL"<<setw(46);
	cout << totGroup[1]<<endl;
	
	
displayLine();
cout <<endl;


cout <<"TEAM "<<marks[9][0]<<endl;
	
	for (int i=8; i<12; i++)
	{
		for (int j=1; j<7; j++)
		{
			cout<<marks[i][j]<<"\t";
		}
		cout<<toteach[i];
		cout<<endl;	
	}
	cout << "TOTAL"<<setw(46);
	cout << totGroup[2]<<endl;
	
	
displayLine();
cout <<endl<<endl;
	
	int highI[2]={0};	
	findIndWinner(marks,toteach,highI);
	int highT[2]={0};
	findTeamWinner(totGroup,marks,highT);
	
	cout << "Winner for Individual Category: "<<highI[0] <<" "<<"(Team "<<highI[1]<<")"<<endl;
	cout << "Winner for Group Category:"<<" Team "<<highT[0] <<" (Score = "<< highT[1]<<")"<<endl<<endl;
	cout <<"Press any key to continue . . . ";


	inp.close();
	return 0;
}
