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

Discussion in 'Programming' started by krishnandu.sarkar, Nov 2, 2009.

Thread Status:
Not open for further replies.
  1. krishnandu.sarkar

    krishnandu.sarkar Simply a DIGITian

    Joined:
    Nov 13, 2007
    Messages:
    4,693
    Likes Received:
    15
    Trophy Points:
    38
    Location:
    Kolkata
    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....
     
  2. shri

    shri Always Fresh!

    Joined:
    May 30, 2004
    Messages:
    191
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mangalore
    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
     
  3. OP
    OP
    krishnandu.sarkar

    krishnandu.sarkar Simply a DIGITian

    Joined:
    Nov 13, 2007
    Messages:
    4,693
    Likes Received:
    15
    Trophy Points:
    38
    Location:
    Kolkata
    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......
     
  4. shri

    shri Always Fresh!

    Joined:
    May 30, 2004
    Messages:
    191
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mangalore
    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.
     
Thread Status:
Not open for further replies.

Share This Page