#Hi

4 messages · Page 1 of 1 (latest)

thin geyser
#

i have a question related to c mostly but can be solved with c++ or any other language as well it is my home task and i am having some trouble these is the input and this is the question:
The coordinates of points are given on a plane. Sort them in increasing order of sum of coordinates. In the case of equal sum of point coordinates sort the points in increasing order of abscissa.

Input
Each line contains the pair of numbers x, y (0 ≤ x, y ≤ 10^9) - the coordinates of one point. The number of points does not exceed 10^5. Read the points till the end of file.

Output
Print the points in the specified order.

lucid ferryBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

wraith wagon
#

I'd say you need:

  • a struct
  • a looooong array (should aim for heap here)
  • a comparator function
  • qsort() - from the stlib.h header

Unless the assignment says you need to implement your own sorting algorithm.

#

For bonus points you could use the top answer to this SO question to work out how long your array should be exactly:
https://stackoverflow.com/questions/12733105/c-function-that-counts-lines-in-file

But then we are making the (safe?) assumption that there are no comments / empty lines in the file.
You'd also need to fseek() back to the start of the file afterwards, so you can then start actually reading the data from the file and fill in the array.