Need Help In a C Program...Plz Help Me Out

Status
Not open for further replies.

krishnandu.sarkar

Simply a DIGITian
Staff member
Define a structure called cricket that will describe the following information:
1. Player_Name
2. Team_Name
3. Batting_Avg

Using cricket declare an array of 50 elements and write a program to read the information about all the 50 players and print a team wise list containing names of players with their batting avg.

Guys I'm stuckd with this team wise printing part.

Say a user entered players of team in this manner
india-india-australia-pakistan-india-pakistan-australia

So I need to print 3 India players thn 2 australia players and than 2 Pak players.

Now a diff user can enter different team name and in different manner

So how shud i sort the array according to team name or simply print it team wise.

Plz help....
 

shri

Always Fresh!
Sorting is one option. But involves a little bit of work.

Or you can do this:
Read the team name of the first structure.
Compare this name with the rest of the structures
Print player name when the team names are matching
 
OP
krishnandu.sarkar

krishnandu.sarkar

Simply a DIGITian
Staff member
Or you can do this:
Read the team name of the first structure.
Compare this name with the rest of the structures
Print player name when the team names are matching

Well I tried this.......

But say......I insert the team name in the array in this sequence

Ind-Aus-Pak-Ind-Aus-Pak-Ind-Aus-Pak

Now all Ind gets printed....

Now I'm stuck how to get the Aus from that array and make sure that Ind doesnt gets printed again......
 

shri

Always Fresh!
This is a crude solution.

Maintain a flag array say is_printed[MAX_SIZE].
Initially all entries in the array are 0.
When a particular team player name is printed the corresponding index in the is_printed[] array is made 1.

Ex: ind-aus-pak-ind-aus-aus-pak = 7 players
Before printing any : is_printed[] = {0,0,0,0,0,0,0}
After printing ind players: is_printed[] = {1,0,0,1,0,0,0}

Now, during the second iteration, when you need to print the aus players, do a check on the is_printed array and skip the structure for the index having a 1 in the is_printed array. i.e you'll skip the 0th nad the 3rd structure.
 
Status
Not open for further replies.
Top Bottom