|
|
|
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
パソコン甲子園例題
#include<stdio.h>
#include<stdlib.h>
#define NUM 5
void s_sort(int []);
int main()
{
int i, a[NUM];
char buffer[50];
for(i = 0; i < NUM; ++i) {
fgets(buffer, sizeof(buffer), stdin);
a[i] = atoi(buffer);
}
s_sort(a);
for(i = 0; i < NUM; ++i) {
printf("%d\n", a[i]);
}
return 0;
}
void s_sort(int a[])
{
int i, j, pos, tmp;
for(i = 0; i < NUM - 1; ++i) {
pos = i;
tmp = a[pos];
for(j = i + 1; j < NUM; ++j) {
if(tmp < a[j]) {
pos = j;
tmp = a[pos];
}
}
a[pos] = a[i];
a[i] = tmp;
}
return;
} |