#include<iostream>
#include <fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;

void displayLine() 
{
	int i;
	for (i=0; i<54 ; i++)
	{
	 cout << "-";
	}
	 cout << endl;
}


void findTeamWinner( int teammarks [])
{
	int winnerteam;
	int highest = teammarks[0];
	for (int i=0; i<3 ;i++)
	{
		if (teammarks[i]>highest)
		{
			highest=teammarks[i];
			winnerteam=i+1;
		}
	}
	
		cout<<"Winner for Group Category: " << " Team "<< winnerteam<<" (Score = "<< highest<<")";
	
}

void findIndWinner(int marks [][7],int totmarkin[])
{
	int in;
	int highest = totmarkin[0];
	for (int i=0; i<12 ;i++)
	{
		if (totmarkin[i]>highest)
		{
			highest=totmarkin[i];
			in=i;
		}
	}
	
	cout<<"Winner for Individual Category:  " <<marks[in][1]<< " (Team "<<marks[in][0]<<")"<<endl;
	
}

int main ()
{

    int k=0, i,j, marks[12][7], highest, totmarkin[12], teammarks[3];

	ifstream inp;
	inp.open("input2.txt");
	
	if (!inp)
	{
		cout << "Sorry, input file does not exist!" << endl;
		exit(0);
		
	}
	
	for (int i=0 ; i<12 ; i++) //insert data
	{
			for (j=0;j<7; j++)
			{
				inp>>marks[i][j];
			}
	}
	
	for (int i=0 ; i<12 ; i++)
	{
		int total=0;
			for (j=2;j<7; j++)
			{
					total += marks[i][j];		
			}
			
		totmarkin[i]=total;
	}
	
		for (int i=0 ; i<3 ; i++)
	{
			if(i==0)
			{
				int total1=0;
				for(int l=0;l<4;l++)
				{
					total1+=totmarkin[l];
				}
				teammarks[i]=total1;	
				
			}
			
			else if(i==1)
			{
				int total1=0;
				for(int l=4;l<8;l++)
				{
					total1+=totmarkin[l];
				}
				teammarks[i]=total1;	
			}
			
			else
			{
				int total1=0;
				for(int l=8;l<12;l++)
					{
						total1+=totmarkin[l];
					}
				teammarks[i]=total1;		
			}
		
	}
	
	displayLine();
	cout<<left;
	cout<< setw(8) << "Id" << setw(8) << "E1" << setw(8) << "E2" << setw(8) << "E3" << setw (8) << "E4" << setw(8) << "E5" << setw(8) << "Total"<<endl;
	displayLine();
	
		cout<<"TEAM 1" <<endl;
		for(int i=0;i<4;i++)
		{
			cout<<setw(8)<<marks[i][1];
			for(int k=2;k<7;k++)
				cout<<setw(8)<<marks[i][k];
				
			cout<<" "<< totmarkin[i];
			cout<<endl;
			
		}
		cout<<endl;
		cout<<setw(49)<<"Total"<<teammarks[0]<<endl;
		displayLine();
		
		cout<<"TEAM 2"<<endl;
		for(int i=4;i<8;i++)
		{
			cout<<setw(8)<<marks[i][1];
			for(int k=2;k<7;k++)
				cout<<setw(8)<<marks[i][k];
			cout<< " " << totmarkin[i];
			cout<<endl;
		}
		cout<<endl;
		cout<<setw(49)<<"Total"<<teammarks[1]<<endl;
		displayLine();
		
		cout<<"TEAM 3"<<endl;
		for(int i=8;i<12;i++)
		{
			cout<<setw(8)<<marks[i][1];
			for(int k=2;k<7;k++)
				cout<<setw(8)<<marks[i][k];
			cout<< " " << totmarkin[i];
			cout<<endl;
		}
			cout<<endl;
			cout<<setw(49)<<"Total"<<teammarks[2]<<endl;
			displayLine();
	
	findIndWinner(marks ,totmarkin);
	findTeamWinner(  teammarks );
	

	inp.close();
		
}
	
	



