#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;

const int NUM_STATE = 14;
const int NUM_YEAR = 10;
ofstream out ("output.txt");

struct dataAcc{
	int numAcc[10];
	string state;
	float avg;
};

void displayLine();
float cal_Avg(int []);
void find_HighLow(dataAcc []);

int main()
{
	dataAcc accident[NUM_STATE];
	
	ifstream input("input1.txt");
	if(!input)
	{
		cout<<"Error:Cant open file\n";
		exit(1);
	}
	for(int i=0;i<NUM_STATE;i++)
	{
		for(int j=0;j<NUM_YEAR;j++)
		    input>>accident[i].numAcc[j];
		getline(input,accident[i].state);
	}
	for(int i=0;i<NUM_STATE;i++)
	{
		accident[i].avg = cal_Avg(accident[i].numAcc);
	}
	displayLine();
	out<<setw(10)<<"STATE"<<setw(10)<<" ";
	for(int i=2006;i<=2015;i++)
	{
		out<<i<<setw(7);
	}
	out<<setw(10)<<"AVERAGE"<<endl;
	displayLine();
	out<<fixed<<showpoint<<setprecision(1);
	for(int i=0;i<NUM_STATE;i++)
	{
		out<<left<<setw(17)<<accident[i].state<<right;
		for(int j=0;j<NUM_YEAR;j++)
			out<<setw(7)<<accident[i].numAcc[j];
		out<<setw(10)<<accident[i].avg<<endl;
	}
	displayLine();
	find_HighLow(accident);
	displayLine();
	input.close();
	out.close();
	return 0;
	
}
void displayLine()
{
	for (int i = 0; i < 98; i++)
	out << "-";
	out << endl;
}
float cal_Avg(int num[])
{
	int total=0;
	for(int i=0;i<NUM_YEAR;i++)
	{
		total+=num[i];
	}
	return static_cast<float>(total)/NUM_YEAR;
}
void find_HighLow(dataAcc a[])
{
	int highest=0,highindex,yearindex;
	for(int i=0;i<NUM_STATE;i++)
	{
		for(int j=0;j<NUM_YEAR;j++)
		{
			if(a[i].numAcc[j]>highest)
			{
				highest = a[i].numAcc[j];
				highindex = i;
				yearindex=j;
			}
		}
	}
	out<<"The highest number of road accidents = "<<highest<<" at"<<a[highindex].state<<" on "<<2006+yearindex<<endl;
}










