I'm entering a programming competitions, and this is one of the practice problems:

Problem #10

NASCAR’s Nextel Cup Winner

NASCAR officials need your help to determine who won this year’s Race for the Nextel Cup. The person in charge of recording the results of each race was Joe Bob. Unfortunately for NASCAR, Joe Bob math's skills are different than ours. He can only comprehend binary numbers and writes them in groups of 3 digits. In addition to this he is very afraid of computers and refuses to record binary numbers using 0’s and 1’s. He prefers to use U’s in place of 1’s and L’s in place of 0’s. Therefore if Joe Bob wanted to write the decimal number 4 he would write ULL.

Base 2 Base 10

====== =======

0 0

1 1

10 2

11 3

100 4

101 5

110 6

111 7

Joe Bob has recorded the results of all the races in an n x m matrix where n is the number of races and m is the number of drivers. The number of races are never more than 7 and neither is the number of drivers. He recorded the information such that if driver number 5 finished fifth in the first race then the value of matrix[1][5] will be ULU(5).

At this point NASCAR is only interested in who won the Cup. As the chief programmer of NASCAR, write a program to determine who won the cup. Do this by totaling all the finishing positions for each driver. The lowest total wins. For example, given 2 races and 2 drivers with driver 1 finishing first in both races driver 1’s total will be 2 and driver 2’s total will be 4. Thus driver 1 would win the cup. The output of your program should be the number of the driver that won the Cup.

Sample Run 1:

Please enter the number of races: 2

Please enter the number of drivers: 2

Please enter Joe Bob’s data:

LLU LUL

LLU LUL

The winner of the Nextel Cup is driver number 1.

Sample Run 2:

Please enter the number of races: 5

Please enter the number of drivers: 5

Please enter Joe Bob’s data:

ULU LLU LUL ULL LUU

LLU ULU ULL LUU LUL

ULU ULL LUU LUL LLU

LUL ULU LUU ULL LLU

LLU ULU ULL ULU LUL

The winner of the Nextel Cup is driver number 5.

This is how far I've gotten, but I've hit a little snag.

#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <string>

using namespace std;

int i, j;

void Get_Parameters()

{

cout << "Please enter the number of races: ";

cin >> i;

cout << "Please enter the number of drivers: ";

cin >> j;

}

int main()

{

Get_Parameters();

char data[i][(3*j)+4];

cout << "Please enter Joe Bob's Data:" << endl << endl;

int count, coun;

for (count = 0; count <= i; count++)

{

cin >> data[count];

}

for (count = 0; count <= i; count++)

{

for (coun = 0; coun <= j; coun++)

{

if (data[count][coun]= 'U')

{

data[count][coun]= 1;

}

if (data[count][coun]= 'L')

{

data[count][coun]= 0;

}

}

}

system("PAUSE");

return 0;

}

Any help would be much appreciated.

Problem #10

NASCAR’s Nextel Cup Winner

NASCAR officials need your help to determine who won this year’s Race for the Nextel Cup. The person in charge of recording the results of each race was Joe Bob. Unfortunately for NASCAR, Joe Bob math's skills are different than ours. He can only comprehend binary numbers and writes them in groups of 3 digits. In addition to this he is very afraid of computers and refuses to record binary numbers using 0’s and 1’s. He prefers to use U’s in place of 1’s and L’s in place of 0’s. Therefore if Joe Bob wanted to write the decimal number 4 he would write ULL.

Base 2 Base 10

====== =======

0 0

1 1

10 2

11 3

100 4

101 5

110 6

111 7

Joe Bob has recorded the results of all the races in an n x m matrix where n is the number of races and m is the number of drivers. The number of races are never more than 7 and neither is the number of drivers. He recorded the information such that if driver number 5 finished fifth in the first race then the value of matrix[1][5] will be ULU(5).

At this point NASCAR is only interested in who won the Cup. As the chief programmer of NASCAR, write a program to determine who won the cup. Do this by totaling all the finishing positions for each driver. The lowest total wins. For example, given 2 races and 2 drivers with driver 1 finishing first in both races driver 1’s total will be 2 and driver 2’s total will be 4. Thus driver 1 would win the cup. The output of your program should be the number of the driver that won the Cup.

Sample Run 1:

Please enter the number of races: 2

Please enter the number of drivers: 2

Please enter Joe Bob’s data:

LLU LUL

LLU LUL

The winner of the Nextel Cup is driver number 1.

Sample Run 2:

Please enter the number of races: 5

Please enter the number of drivers: 5

Please enter Joe Bob’s data:

ULU LLU LUL ULL LUU

LLU ULU ULL LUU LUL

ULU ULL LUU LUL LLU

LUL ULU LUU ULL LLU

LLU ULU ULL ULU LUL

The winner of the Nextel Cup is driver number 5.

This is how far I've gotten, but I've hit a little snag.

#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <string>

using namespace std;

int i, j;

void Get_Parameters()

{

cout << "Please enter the number of races: ";

cin >> i;

cout << "Please enter the number of drivers: ";

cin >> j;

}

int main()

{

Get_Parameters();

char data[i][(3*j)+4];

cout << "Please enter Joe Bob's Data:" << endl << endl;

int count, coun;

for (count = 0; count <= i; count++)

{

cin >> data[count];

}

for (count = 0; count <= i; count++)

{

for (coun = 0; coun <= j; coun++)

{

if (data[count][coun]= 'U')

{

data[count][coun]= 1;

}

if (data[count][coun]= 'L')

{

data[count][coun]= 0;

}

}

}

system("PAUSE");

return 0;

}

Any help would be much appreciated.

Topic archived. No new replies allowed.