排列习题

来源:互联网 发布:三国志9威力加强版mac 编辑:程序博客网 时间:2024/05/29 02:24
#include <stdio.h>void quicksort(int *a,int left,int right){  int temp,j,i,t;  if(left > right) return;    temp=a[left];  i = left;  j = right;  while(i != j){  while(a[j] >= temp && i < j) j--;  while(a[i] <= temp && i < j) i++;  if(i < j){  t = a[i];  a[i] = a[j];  a[j] = t;   }  }  a[left] = a[i];  a[i] = temp;   quicksort(a,left,i-1);  quicksort(a,i+1,right);  return;} int main(){int i,n,a[1001],k=0,m,b[1001];   scanf("%d",&n);for(i = 1;i <= n; i++){ scanf("%d",&a[i]);} for(i = 0;i < n; i++){  for(m = 0;m < k+1; m++){  if(a[i] == b[m]){  i++;  break;  }  }  b[k++] = a[i];}//去重quicksort(a,1,n);for(i = 1;i <= n; i++){  printf("%d ",a[i]);} return 0;}  

0 0