forked from ankitsamaddar/blind75_cpp_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path32_String Sorting.cpp
More file actions
44 lines (40 loc) · 825 Bytes
/
Copy path32_String Sorting.cpp
File metadata and controls
44 lines (40 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// DATE: 04-07-2023
/* PROGRAM: 32_String Sorting
Input N and n strings and sort it in descending order lexicographically.
INPUT
3
Apple
Pineapple
Green Apple
OUTPUT
Pineapple
Green Apple
Apple
EXPLANATION
- greater<string>() to give comparator to sort in descending order
- for (range-declaration : range-expression) to iterate over the items of the string array
*/
// @ankitsamaddar @2023
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n=0;
cin >> n;
string s[n]; // array can also be taken as vector
cin.get();
for (int i = 0; i<n; i++) {
getline(cin,s[i]);
} cout << endl;
/* To print the strings
for (string it : s) {
cout<<it<<endl;
} cout << endl;
*/
sort(s,s+n,greater<string>());
for (string it : s) {
cout<<it<<endl;
}
return 0;
}