题解 | #明明的随机数#

明明的随机数

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

#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a;
    int snum[1000] = {0};
    int s = 0;
    while (cin >> b) {
        bool key = true; // 注意 while 处理多个 case

        if(s == 0){
            snum[s] = b;
        }
        for(int temp=0; temp<s; temp++){
            if(snum[temp] == b){
                key = false;
                break;
            }
        }
        if(key){
            for(int temp = 0; temp < s; temp++){
                if(b < snum[temp]){
                    for(int kk = s; kk >= temp; kk--){
                        snum[kk+1] = snum[kk];
                    }
                    snum[temp] = b;
                    break;
                }else if(snum[temp+1]==0){
                    snum[temp+1] = b;
                    break;
                }
            }
            s++;
        }

    }
    int yu = 0;
    while(yu<s){
        cout<<snum[yu]<<endl;
        yu++;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

程序员小白条:学历GG,这个排版布局,还有行间距和字缩进不大行,女生自我要求应该更高才是,没内容,起码美观这块要做好
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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