Go Back   Digit's Technology Discussion Forum > Across The Board > Programming

Programming The destination for developers - C, C++, Java, Python and the lot

Reply
 
Thread Tools Search this Thread Display Modes
Old 02-11-2009, 07:03 PM   #1
krishnandu.sarkar
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 601
Unhappy Need Help In a C Program...Plz Help Me Out

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....
__________________
kIlL pIrAcY....................sTeAl OrIgInAl Cd's
krishnandu.sarkar is offline   Reply With Quote

Old 04-11-2009, 12:55 PM   #2
shri
Always Fresh!
 
shri's Avatar
 
Join Date: May 2004
Location: Mangalore
Posts: 166
Default Re: Need Help In a C Program...Plz Help Me Out

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
__________________
BE YOURSELF
http://everythingoutthere.co.cc
shri is offline   Reply With Quote
Old 04-11-2009, 06:31 PM   #3
krishnandu.sarkar
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 601
Default Re: Need Help In a C Program...Plz Help Me Out

Quote:
Originally Posted by shri View Post
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......
__________________
kIlL pIrAcY....................sTeAl OrIgInAl Cd's
krishnandu.sarkar is offline   Reply With Quote
Old 05-11-2009, 09:47 AM   #4
shri
Always Fresh!
 
shri's Avatar
 
Join Date: May 2004
Location: Mangalore
Posts: 166
Default Re: Need Help In a C Program...Plz Help Me Out

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.
__________________
BE YOURSELF
http://everythingoutthere.co.cc
shri is offline   Reply With Quote
Reply

Bookmarks


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Post ur C/C++ Programs Here Gigacore Programming 599 02-11-2009 06:59 PM
Installing software from source in Linux topgear Tutorials 5 11-03-2008 01:52 PM
<<<< Help Plz Help >>> ::cyborg:: QnA 2 14-10-2007 07:37 PM
CHALLENGING C PROGRAM...-atleast for me vinit suri QnA 11 11-10-2007 09:46 PM
Help me plz plz plz n plz The Incredible QnA 4 24-05-2005 08:25 PM

Upcoming Events





Think diget  
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.