Discuz! Board

 找回密码
 立即注册
查看: 377|回复: 3

11.24 桶排序

[复制链接]

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
发表于 2022-11-24 19:39:04 | 显示全部楼层 |阅读模式
本帖最后由 开朗的朱伟宸 于 2022-11-26 10:34 编辑

[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int t[10]={0};
void shuru()
{
        int n;
    for(int i=0;i<10;i++)
        {
            cin>>n;
            t[n]++;
        }
}
void shuchu()
{
        cout<<endl;
        for(int j=0;j<10;j++)
        {
                for(int l=0;l<t[j];l++)
                {
                        cout<<j<<" ";
                }
        }
}
int main()
{
    shuru();
    shuchu();
    return 0;
}
回复

使用道具 举报

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
 楼主| 发表于 2022-11-26 10:34:33 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int n,k;
int t[100]={0};
void shuru()
{
        cin>>k;
    for(int i=0;i<k;i++)
        {
            cin>>n;
            t[n]++;
        }
}
void shuchu()
{
        cout<<endl;
        for(int i=0;i<100;i++)
        {
                for(int j=1;j<=t;j++)
                {
                        cout<<i<<" ";
                }
        }
}
int main()
{
        shuru();
        shuchu();
    return 0;
}
回复

使用道具 举报

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
 楼主| 发表于 2022-11-26 10:35:32 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int n,k;
int t[100]={0};
void shuru()
{
        cin>>k;
    for(int i=0;i<k;i++)
        {
            cin>>n;
            t[n]++;
        }
}
void shuchu()
{
        cout<<endl;
        for(int i=100;i>=0;i--)
        {
                if(t)cout<<i<<" ";
        }
}
int main()
{
        shuru();
        shuchu();
    return 0;
}
回复

使用道具 举报

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
 楼主| 发表于 2022-11-26 10:36:17 | 显示全部楼层
[C++] 纯文本查看 复制代码
#include <bits/stdc++.h>
using namespace std;
int n,k;
int t[2000]={0};
void shuru()
{
        cin>>k;
    for(int i=0;i<k;i++)
        {
            cin>>n;
            t[n+1000]++;
        }
}
void shuchu()
{
        cout<<endl;
        for(int i=0;i<=2000;i++)
        {
                for(int j=1;j<=t;j++)
                {
                        cout<<i-1000<<" ";
                }
        }
}
int main()
{
        shuru();
        shuchu();
    return 0;
}

回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-7-18 07:55 , Processed in 0.073228 second(s), 26 queries .

Powered by Discuz! X3.4

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

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