十大経典ソートアルゴリズム
文書ディレクトリ資料 例題 1:バケツソート例題 (1)成績ランキング 問題 コード 資料
バケツソートバケツソートコードを保存
例題
1:バケツソート例題
(1)成績順位
に質問
Problem Descriptionプログラミングでは配列が大きな役割を果たすことができるが,この問題は一例である.
Input入力には複数のテストケースがあり、各テストケースには1行があり、まず整数n(n<=5000000)であり、次に各学生の成績Ai(0<=Ai<=100)を表すn個の整数がある.
Outputは各テストケースについて、大きいものから小さいものまでの成績を出力し、各テストケースの出力は1行を占める.2つの数字の間にスペースがあり、行末にスペースがありません.
この問題は、データを再アップロードし、再判定したことに注意してください.クイックソートアルゴリズムによるタイムアウト(2017-09-05)
SampleInput 5 80 90 100 70 60 4 20 30 50 20
SampleOutput 100 90 80 70 60 50 30 20 20
コード#コード#
バケツソートバケツソートコードを保存
例題
1:バケツソート例題
(1)成績順位
に質問
TimeLimit:2000MS MemoryLimit:16MB
Problem Descriptionプログラミングでは配列が大きな役割を果たすことができるが,この問題は一例である.
Input入力には複数のテストケースがあり、各テストケースには1行があり、まず整数n(n<=5000000)であり、次に各学生の成績Ai(0<=Ai<=100)を表すn個の整数がある.
Outputは各テストケースについて、大きいものから小さいものまでの成績を出力し、各テストケースの出力は1行を占める.2つの数字の間にスペースがあり、行末にスペースがありません.
この問題は、データを再アップロードし、再判定したことに注意してください.クイックソートアルゴリズムによるタイムアウト(2017-09-05)
SampleInput 5 80 90 100 70 60 4 20 30 50 20
SampleOutput 100 90 80 70 60 50 30 20 20
コード#コード#
#include<bits/stdc++.h>
using namespace std;
const int maxsize=1e2+5;
int a[maxsize];
//
void input(int * a,int n) // ,
{
int i =0;
int core;
for(; i<=100; i++)
a[i] = 0; // 0
for(i = 0; i<n; i++)
{
scanf("%d",&core); //
a[core]++; //
}
}
//
void descending(int *a,int n)
{
int i = 101,sum=0;
int j;
for(; i>=0; i--) // , a[0] ~ a[100]
for(j = 1; j <= a[i] ; ++ j) //
{
printf("%d",i);
if(sum<n-1){
cout<<" ";
sum++;
}
}
}
int main() {
// your code goes here
int n;
int flag=0;
while(scanf("%d",&n)!=EOF){
input(a,n);
descending(a,n);
cout<<endl;
}
return 0;
}