Print rows in desired sorted order.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
i need the answer quickly
Problem A. Sorter
C++ code
Input file:
Output file:
Time limit:
standard input
standard output
1 second
256 megabytes
Memory limit:
Almas loves to sort mumbers with specific rules that he comes up with himself. Today he wants to sort
rows, each row contain m integer elements. He decided to sort rows in decreasing order of their sum, i.e.
the row with larger sum will be the first. In case the sums are equal, then he order rows lexicographically,
ie. The row with least first element will be the first, if first elements are equal, then compare second
element, third element, etc. He successfiully finished sorting. He wanted to put the result in the closet, but
accidentally put it in the shredder and divided everything into rows again. Help him sort it again.
Input
The first line contains two numbers, n and m the number of rows and mumber of elements in a row. The
next n lines contain m numbers, elements of each row.
•1sn,m s 500
•0 S rowli) < 5000
Output
Print rows in desired sorted order.
Examples
standard input
standard output
5 3
124
1 2 3
23 2
124
123
132
13 2
600
600
2 3 2
2 3
16 3 18
5 10 8
16 3 18
5 10 8
55
29 8 50 21 43
17 16 21 10 48
45 44 29 8 24
1 34 5 41 42
1 34 5 41 42
29 8 50 21 43
21 39 9 26 23
21 39 9 26 23
17 16 21 10 48
45 44 29 8 24
Transcribed Image Text:Problem A. Sorter C++ code Input file: Output file: Time limit: standard input standard output 1 second 256 megabytes Memory limit: Almas loves to sort mumbers with specific rules that he comes up with himself. Today he wants to sort rows, each row contain m integer elements. He decided to sort rows in decreasing order of their sum, i.e. the row with larger sum will be the first. In case the sums are equal, then he order rows lexicographically, ie. The row with least first element will be the first, if first elements are equal, then compare second element, third element, etc. He successfiully finished sorting. He wanted to put the result in the closet, but accidentally put it in the shredder and divided everything into rows again. Help him sort it again. Input The first line contains two numbers, n and m the number of rows and mumber of elements in a row. The next n lines contain m numbers, elements of each row. •1sn,m s 500 •0 S rowli) < 5000 Output Print rows in desired sorted order. Examples standard input standard output 5 3 124 1 2 3 23 2 124 123 132 13 2 600 600 2 3 2 2 3 16 3 18 5 10 8 16 3 18 5 10 8 55 29 8 50 21 43 17 16 21 10 48 45 44 29 8 24 1 34 5 41 42 1 34 5 41 42 29 8 50 21 43 21 39 9 26 23 21 39 9 26 23 17 16 21 10 48 45 44 29 8 24
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education