#include <iostream> // JACK LEE /990212-01-5315/ A19EC0057 / SECTION 07 / 26.11.2019
#include <fstream> // MUHAMMAD SUHAIL / C0082352 / A19EC0269 / SECTION 07 / 26.11.2019
#include <iomanip>
using namespace std ;

void displayLine();
void findIndWinner(int total[12], int marks[12][7]);
void findTeamWinner(int TOTAL[3]);

int main ()
{
	int marks[12][7],n, m,total[12] , total1 = 0 , TOTAL1 = 0 , TOTAL[3];
	ifstream in;
	in.open("input2.txt");
	
	if (!in)
	{
		cout << "Sorry, input file does not exist! " << endl ;
		cout << "Press any key to continue . . . " << endl ;
	}
	
	for(int i = 0 ; i < 12 ; i ++)
	{
		
		for (int j = 0 ; j < 7 ; j ++)
		{
			in >> marks[i][j] ;
		}	
	}
	displayLine() ;
	cout << "Id" << setw(8) << "E1" ;
	cout << setw(8) << "E2" << setw(8) << "E3" << setw(8) ;
	cout << setw(8) << "E4" << setw(8) << "E5" << setw(10) << "Total" << endl ;
	displayLine() ;
	
	for (int a = 0 ; a < 3 ; a++)
	{
		m = 4*a + 0 ;
		cout << "TEAM  " << marks[m][0] << endl ;
		for (int b = 0 ; b < 4 ; b ++)
		{
			n = 4*a + b ;
			cout << marks[n][1] << "    "  ;
			for (int c = 2 ; c < 7 ; c ++)
			{
				cout << setw(8) << left << marks[n][c] ;
				total1 = total1 + marks[n][c] ;
				total[n] = total1 ;
			}
			cout << total[n] ;
			TOTAL1 = TOTAL1 + total1 ;
			total1 = 0 ;
			cout << endl ;
		}
		TOTAL[a] = TOTAL1 ;
		TOTAL1 = 0 ;
		cout << "TOTAL" << setw(46) << right << TOTAL[a] << endl ;
		displayLine() ;			
	}
	findIndWinner(total, marks) ;
	findTeamWinner(TOTAL) ;
	cout << "Press any key to continue . . ." ;
	return 0 ;
}

void displayLine()
{
	for (int i = 0 ; i < 52 ; i ++)
	{
		cout << "-" ;
	}
	cout << endl ;
}

void findIndWinner(int total[12], int marks[12][7])
{
	int winner = -999 , w ; 
	for (int i = 0 ; i < 12 ; i ++)
	{
		if(total[i] > winner )
		{
			winner = total[i] ;
			w = i ;
		}
	}
	cout << "Winner for Individual Category: " << marks[w][1] ;
	cout << " (Team " << marks[w][0] << ")" << endl ;
	
}

void findTeamWinner(int TOTAL[3])
{
	int winner = -999, w ;
	for (int i = 0 ; i < 3 ; i ++)
	{
		if (TOTAL[i] > winner)
		{
			winner = TOTAL[i] ;
			w = i ;
		}
	}
	cout << "Winner for Group Category: Team " << w+1 ;
	cout << " (Score = " << winner << ")" << endl ;
	cout << endl ;
}
