Discuz! Board

 找回密码
 立即注册
查看: 352|回复: 1

选择

[复制链接]

51

主题

54

帖子

8724

积分

论坛元老

Rank: 8Rank: 8

积分
8724

大牙狸 Lv:12
发表于 2022-12-15 19:35:28 | 显示全部楼层 |阅读模式
#include<bits/stdc++.h>
using namespace std;
int a[100],temp=0,j;
int main()
{
        srand(time(0));
        for(int i=0;i<10;i++)
        {
                a[i]=rand();
                cout<<a[i];
                cout<<endl;
        }
        for(int i=0;i<10;i++)
        {
                temp++;
                for(j=i+1;j<10;j++)
                {
                        if(a[temp]>a[j])
                        {
                                temp=j;
                        }
                }
                swap(a[i],a[temp]);
        }
        for(int i=0;i<10;i++)
        {
                cout<<a[i]<<" ";
        }
}
回复

使用道具 举报

719

主题

906

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11898
发表于 2022-12-15 20:27:41 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include<bits/stdc++.h>
using namespace std;
int a[100],temp=0,j;
int main()
{
    srand(time(0));
    for(int i=0;i<10;i++)
    {
        a[i]=rand();
        cout<<a[i];
        cout<<endl;
    }
    for(int i=0;i<10;i++)
    {
        temp=i;//temp++ 
        for(j=i+1;j<10;j++)
        {
            if(a[temp]>a[j])
            {
                temp=j;
            }
        }
        swap(a[i],a[temp]);
    }
    for(int i=0;i<10;i++)
    {
        cout<<a[i]<<" ";
    }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-7-18 11:15 , Processed in 0.064296 second(s), 29 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表