如果输入2 1 3 4 5 6 7 8 10 9,则输出1 2 3 4 5 6 7 8 9 10,如果输入17 1 2 3 4 5 6 7 8 9,则输出 1 9 2 3 4 5 6 7 8 17
时间: 2024-01-10 20:02:25 浏览: 19
这道题目可以使用一个桶排序的思想,将输入的数按照顺序放入对应的位置,最后输出即可。具体实现可以参考下面的代码:
```python
nums = input().split()
max_num = max([int(num) for num in nums])
buckets = [0] * (max_num + 1)
for num in nums:
buckets[int(num)] = num
res = []
for num in buckets:
if num != 0:
res.append(num)
print(" ".join(res))
```
对于输入 2 1 3 4 5 6 7 8 10 9,输出为 1 2 3 4 5 6 7 8 9 10;对于输入 17 1 2 3 4 5 6 7 8 9,输出为 1 9 2 3 4 5 6 7 8 17。
相关问题
用C语言输入1 2 3 4 5 6 7 8 9 10
可以使用循环语句 for 来输入这些数,如下所示:
```c
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++) {
printf("%d ", i);
}
return 0;
}
```
输出结果为:1 2 3 4 5 6 7 8 9 10
c语言输入1 2 3 4 5 6 7 8 9输出1 9 2 8 3 7 4 6 5
以下是C语言实现输入1 2 3 4 5 6 7 8 9输出1 9 2 8 3 7 4 6 5的代码:
```c
#include <stdio.h>
#define MAX_SIZE 9
int main() {
int arr[MAX_SIZE];
int i, j;
// 输入数组
for (i = 0; i < MAX_SIZE; i++) {
scanf("%d", &arr[i]);
}
// 输出数组
for (i = 0, j = MAX_SIZE - 1; i < j; i++, j--) {
printf("%d %d ", arr[i], arr[j]);
}
// 如果数组长度为奇数,输出中间的数
if (i == j) {
printf("%d", arr[i]);
}
return 0;
}
```
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)