luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/NUMTRANS?fbclid=IwAR1CH774zujzfSXVuUBjhTRWoxB5_xDaw14c4Y6sY23kMVeaF3nhKhDBt1Y #877

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Chi tiết bài tập - Luyện Code Online

https://oj.luyencode.net/problem/NUMTRANS?fbclid=IwAR1CH774zujzfSXVuUBjhTRWoxB5_xDaw14c4Y6sY23kMVeaF3nhKhDBt1Y

rimurey commented 1 year ago

Bài này ta chỉ cần tư duy đơn giản là: sắp xếp các số đã cho theo thứ tự giảm (hoặc tăng) dần của thứ tự từ điển (theo thứ tự từ điển: '19' < '9'). Sau đó in lần lượt từ đầu tới cuối (hoặc cuối lên đầu). Khi đó các chữ số sẽ ưu tiên từ '9' tới '1' để đạt được giá trị lớn nhất

Đây là code C++ đã AC bạn có thể tham khảo ```cpp #include using namespace std; int main() { int n; cin >> n; string s[n]; for (int i = 0; i < n; ++i) { cin >> s[i]; } sort(s, s+n, greater()); for (int i = 0; i < n; ++i) { cout << s[i]; } return 0; } ```