本文共 941 字,大约阅读时间需要 3 分钟。
#include #include #include #include #include #include using namespace std;int main() { vector res; int t; for (int i = 0; i < 10; i++) { cin >> t; for (int j = 0; j < t; j++) { res.push_back(i); } } sort(res.begin(), res.end()); if (res[0] == 0) { for (int i = 1; i < res.size(); i++) { if (res[i] != 0) { swap(res[i], res[0]); break; } } } for (int i = 0; i < res.size(); i++) cout << res[i]; return 0;}复制代码
def main(): a = input().split() res = [] for i in range(10): for j in range (int(a[i])): res.append(str(i)) res.sort() for i in range(len(res)): if(res[i] != '0'): res[i],res[0] = res[0],res[i] break print(''.join(res))main()复制代码
转载于:https://juejin.im/post/5ce93eede51d45775a70027e