#include <stdio.h> void BubbleSort(int a[], int len){ int i, j, temp; for (j = 0; j < len - 1; j++){ for (i = 0; i < len - 1 - j; i++) if (a[i] < a[i + 1]){ temp = a[i]; a[i] = a[i + 1]; a[i + 1] = temp; } } } int main() { int n,i=0,j=0,temp,len=0; int a[100];//输入的数组 int b[10086] = {0};//求解过程的数组 int c[101] = {0};//最终结果数组 scanf("%d", &n);//输入n do { scanf("%d", &a[i++]); } while (getchar() != '\n'); i = 0; for (j = 0; j < n; j++) { b[a[j]]=a[j]; } while (i<n) { temp = a[i]; while (temp != 1) { if (temp % 2 == 0) { temp /= 2; b[temp] = 0; } else { temp = (temp * 3 + 1) / 2; b[temp] = 0; } } i++; } j = 0; for (i = 0; i < 101; i++) { if (b[i] != 0) { c[j++] = b[i]; len++; } } BubbleSort(c, len);//冒泡排序 i = 0; while (c[i] != 0) { printf("%d%c", c[i++], c[i + 1] ? ' ' : '\0'); } }