Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Cho số nguyên không âm N, hãy tiến hành sắp xếp các chữ số của N theo thứ tự tăng dần rồi in ra màn hình, trong trường hợp số sau khi sắp xếp xuất hiện các chữ số 0 ở đầu thì ra không in những chữ số 0 vô nghĩa này.
Đầu vào
Dòng duy nhất chứa số nguyên dương N
Giới hạn
0<=N<=10^18
Đầu ra
In ra số N sau khi sắp xếp
Ví dụ :
Input 01
999968677
Output 01
667789999
Input 02
2828000
Output 02
2288
Bình luận
Full AC
include <iostream>
include <string>
include <algorithm>
using namespace std;
string sortDigitsAscending(const string& number) { string sortedNumber = number; sort(sortedNumber.begin(), sortedNumber.end()); return sortedNumber; }
string removeLeadingZeros(const string& number) { sizet firstNonZero = number.findfirstnotof('0'); if (firstNonZero == string::npos) return "0"; return number.substr(firstNonZero); }
string processNumber(const string& number) { string sorted = sortDigitsAscending(number); return removeLeadingZeros(sorted); }
int main() { ios::syncwithstdio(false); cin.tie(nullptr);
}
include <stdio.h>
include <stdlib.h>
include <string.h>
include <ctype.h>
int cmp(const void *a, const void *b){ char *x = (char *)a; char *y = (char *)b; return *x - *y; } int main(){ char c[10005]; scanf("%s", c); qsort(c, strlen(c), sizeof(char), cmp); int i = 0; while(c[i] == '0' && i < strlen(c) - 1){ ++i; } for(int j = i; j < strlen(c); j++){ printf("%c", c[j]); } }
Bình luận này đã bị ẩn vì có quá nhiều phản ứng tiêu cực. Nhấn để xem.