文章
18
粉丝
0
获赞
3
访问
10.8k
感谢snake大佬指点,时隔多日总算通过
#include<stdio.h>
#include<stdlib.h>
typedef struct {
int num;
int repeat;//标记是否重复
}number;
void swap(number* a, number* b) {
number temp = *a;
*a = *b;
*b = temp;
}
void BubbleSortUp(number* array, int length)//排序
{
for (int i = 0; i < length - 1; i++) {
for (int j = i + 1; j < length; j++) {
if (array[i].num > array[j].num) {
swap(&array[i], &array[j]);
}
}
}
}
int main() {
int n;
scanf("%d", &n);
int length = n;//记录长度
int x,index;
number* data = (number*)malloc(sizeof(number) * n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
if (i == 0) {//首个数据不需要对比
data[i].num = x;
data[i].repeat = 0;
continue;
}
for (int j = 0; j < i; j++) {//重复数据检测
index = 0;//设置一个标记来判断是否存储
if (x == data[j].num) {//有重复的数据修改数组长度和重复标记
length--;
data[j].repeat = 1;
index = 1;
break;
}
}
if (index)
conti...
登录后发布评论
暂无评论,来抢沙发