SORTROWS - Editorial

Prerequisite :- Sorting, vector
Problem :- Given multiple rows of numbers, Print the rows in lexicographical order. We use -1 to represent the end of a row.

Explanation :- 2D vectors are used to store multiple rows.
To input multiple numbers in a single row, we will use a vector, and to store multiple rows, we will use vectors of vectors. Once all the rows are stored in our 2D vector, we can sort the vector, arranging our rows in lexicographical order, and then print them

Algorithm : -
Input all the numbers of a single row inside a vector.
Once a complete row is input(which we can know through -1), push the vector storing row to a 2D vector.
Once all the rows are pushed, sort the 2D vector and print it.

C++ Solution : -

#include <bits/stdc++.h>
using namespace std;

int main() {
    // your code goes here
    int n;
    cin>>n;
    vector<vector<int>>v1;
    for(int i=0;i<n;i++){
    	vector<int>v2;
    	int num;
    	while(cin>>num){
        	if(num==-1){
            	v1.push_back(v2);
            	break;
        	}
        	v2.push_back(num);
    	}
    }
    sort(v1.begin(),v1.end());
    for(auto e:v1){
    	for(auto f:e){
        	cout<<f<<" ";
    	}
    	cout<<"\n";
    }

}