题解 | 明明的随机数

明明的随机数

https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    
    int n=0;
    int i=0,j=0;
    scanf("%d",&n);
    int *str=malloc(n*sizeof(int));
    int *str2=malloc(n*sizeof(int));int *p=str,*p2=str2;
    while(i++<n){
        scanf("%d",p++);
    }p=str;
    for(i=0;i<n-1;i++){
        for(j=0;j<n-1-i;j++){
            if(str[j]>str[j+1]){
                int t=str[j];
                str[j]=str[j+1];
                str[j+1]=t;
            }
        }
    }
    *p2++=*p++;
    while((p-str)<n){
        if(*(p2-1)!=*p){
            *p2=*p;
            p2++;
        }
        p++;
    }
    for(i=0;i<p2-str2 ;i++){
        printf("%d\n",str2[i]);
    }
    free(str);free(str2);






    return 0;
}

全部评论
自己写的石山小代码
点赞 回复 分享
发布于 04-01 17:10 湖北

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务