You are not logged in. Please login at www.codechef.com to post your questions!

×

[FGFS-JAN14]How to keep connection between arrival and departure timings if I have to sort one of them?

Can anyone please explain the algorithm in detail....and provide the code in C...?Here my doubt is ..I am scanning the arriving times,departure times and preferred places in three different arrays....if I had sorted anyone of them,I would have lost the connection between three of them....How can I get rid of this...?
Thanks in advance...!!!

asked 12 Jul '14, 18:03

neal95's gravatar image

3★neal95
318712
accept rate: 10%

edited 12 Jul '14, 18:33


You can use struct and sort the whole struct using compare function e.g. void comp(struct node a,struct node b) { return a.arr < b.arr; //this will sort the structs according to arrival time. } struct node { int arr,dep,pref; }; node a[1000]; sort(a,a+n,comp);

link

answered 12 Jul '14, 18:53

rahul_nexus's gravatar image

2★rahul_nexus
7741923
accept rate: 13%

thanq u @rahul_nexus

(12 Jul '14, 19:46) neal953★

Use can use pair in the stl library of c++ . You can store them as a pair of number and then sort them , sorting will be done on the basis of first number . You can access elements by using variable.first and variable.second .

pair<int,int> a;
cin>>a.first>>a.second;
sort(a,a+n)
link

answered 12 Jul '14, 21:41

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

thanq u @the65bit

(13 Jul '14, 14:13) neal953★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×801
×51
×3

question asked: 12 Jul '14, 18:03

question was seen: 1,443 times

last updated: 13 Jul '14, 14:13