3015
#include <stdio.h>
typedef struct
{
char name[11];
int score;
}student;
int main()
{
int i,j,m,n;
student a[101];
student temp;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%s %d",a[i].name,&a[i].score);
}
for(i=1;i<n;i++)
{
for(j=1;j<=n-i;j++)
{
if(a[j].score<a[j+1].score)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(j=1;j<=m;j++)
{
printf("%s\n",a[j].name);
}
}
-----------------------------------------------------
3017
#include <stdio.h>
typedef struct
{
int number;
int math;
int score;
} student;
int main()
{
int i,j,n;
student s[1001];
student temp;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d %d",&s[i].math,&s[i].score);
s[i].number=i;
}
for(i=1; i<=n; i++)
{
for(j=1; j<=n-i; j++)
{
if(s[j].math<s[j+1].math)
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
else if(s[j].math==s[j+1].math)
{
if(s[j].score<s[j+1].score)
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
else if(s[j].score==s[j+1].score)
{
if(s[j].number>s[j+1].number)
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
}
}
for(i=1; i<=n; i++)
{
printf("%d %d %d\n",s[i].number,s[i].math,s[i].score);
}
}
--------------------------------
1442
#include <stdio.h>
int a[10001];
int n, i, j, temp, min;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (i=1; i<n; i++) {
min=i;
for (j=i+1; j<=n; j++)
{
if(a[min]>a[j])
{
min=j;
}
}
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
for (i=1; i<=n; i++)
printf("%d\n", a[i]);
return 0;
}
--------------------------------
1420
//선택정렬
/*
#include <stdio.h>
typedef struct
{
char name[11];
int score;
} student;
int main()
{
int n,i,j,s,max=0;
student a[101],temp;
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%s %d",a[i].name,&a[i].score);
}
for(i=1; i<=n; i++)
{
max=i;
for(j=i+1; j<=n; j++)
{
if(a[max].score<a[j].score)
{
max=j;
}
}
temp = a[i];
a[i] = a[max];
a[max] = temp;
}
printf("%s",a[3].name);
}
숙제 :
1709 (구조체정렬 - 버블or선택)
3019 (구조체정렬 - 버블or선택)
4501(선택정렬로)
삽입정렬 진도나가기
*/



