You are viewing a single comment's thread. Return to all comments →
using namespace std;
int main() { int n; cin >> n;
const int MAX_LEN = 100; char arr[100][MAX_LEN]; for (int i = 0; i < n; ++i) { cin >> arr[i]; } for (int i = 0; i < n - 1; ++i) { for (int j = 0; j < n - i - 1; ++j) { int len1 = strlen(arr[j]); int len2 = strlen(arr[j + 1]); if (len1 > len2 || (len1 == len2 && strcmp(arr[j], arr[j + 1]) > 0)) { char temp[MAX_LEN]; strcpy(temp, arr[j]); strcpy(arr[j], arr[j + 1]); strcpy(arr[j + 1], temp); } } } for (int i = 0; i < n; ++i) { cout << arr[i] << endl; } return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Big Sorting
You are viewing a single comment's thread. Return to all comments →
include
include
using namespace std;
int main() { int n; cin >> n;
}