指针问题 —— 排序问题
时间: 1ms 内存:128M
描述:
输入10个整数,将他们从小到大排序后输出,并给出每个元素在原来序列中的位置
//将程序需要的代码补全,只提交begin到end部分的代码
#include <stdio.h>#define N 10int main(){int a[N],b[N],cnt=1,i,j,tmp;int *p,*p1;for(p = a, p1=b ;p < a+N;p++){scanf("%d",p);*(p1++) = cnt++;}for(i = 0;i < N ;i++)for(j = i+1 ;j < N ;j++){if(*(a+i) > *(a+j)){tmp = *(a+i);/********begin*********///Add Code There/*********end********/*(b+j) = tmp;}}for(p=a;p<a+9;p++)printf("%d ",*p);printf("%d\n",*p);for(p=b;p<b+9;p++)printf("%d ",*p);printf("%d\n",*p);return 0;}
输入:
输入数据有一行,包含10个整数,用空格分开。
输出:
输出数据有两行,第一行为排序后的序列,第二行为排序后各个元素在原来序列中的位置。
示例输入:
1 2 3 5 4 6 8 9 10 7
示例输出:
1 2 3 4 5 6 7 8 9 10
1 2 3 5 4 6 10 7 8 9
提示:
参考答案:
解锁文章
运行提交后不对呢