as far as i can tell, in this question we have to sot the numbers in decreasing lexicographical order. i don’t know what function to use for that. so I searched on the net and found this code. why is this not working, and also, how do I sort these numbers lexicographically?
#include
using namespace std;
int main()
{
int t;
cin>>t;
while (t>0)
{
int n;
cin>>n;
string str[n], temp;
cout << "Enter 10 words: " << endl;
for(int i = 0; i < n; ++i)
{
getline(cin, str[i]);
}
// Use Bubble Sort to arrange words
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n - i; ++j) {
if (str[j] > str[j + 1]) {
temp = str[j];
str[j] = str[j + 1];
str[j + 1] = temp;
}
}
}
cout << "In lexicographical order: " << endl;
for(int i = 0; i < 10; ++i)
{
cout << str[i] << endl;
}
t--;
}
return 0;
}