本文主要是介绍歌唱比赛计分 (8 分)设有10名歌手(编号为1-10)参加歌咏比赛,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
未采用结构体的解法,通过二维数组解题
#include <stdio.h>
void rank(int arr[10][6] )
{
int str[4] = { 0 };
int a1[6] = { 0 };
int k = 0;
int i = 0;
int z = 0;
int j = 0;
int temp = 0;
double s1[10][2] = { 0 };
double sum = 0;
int n = 10;
double temp1 = 0;
double temp2 = 0;
while( k != 10 )
{
for( i = 0 ; i < 6 ; i++ )
{
a1[i] = arr[z][i];
}
for( i = 0 ; i < 5 ; i++ )
{
for( j = 0 ; j < 5 - i ; j++ )
{
if(a1[j] > a1[j+1] )
{
temp = a1[j];
a1[j] = a1[j+1];
a1[j+1] = temp;
}
}
}
for( i = 1 ; i < 5 ; i++ )
{
sum = sum + a1[i];
}
sum = sum / 4.0;
for( i = 0 ; i < 2 ; i++ )
{
if( i == 0 )
{
s1[z][i] = z+1;
}
else
{
s1[z][i] = sum;
}
}
z++;
k++;
sum = 0;
}
for( i = 0 ; i < 9 ; i++ )
{
for( j = 0 ; j < 9 - i ; j++)
{
if( s1[j][1] < s1[j+1][1] )
{
temp1 = s1[j][0];
temp2 = s1[j][1];
s1[j][0] = s1[j+1][0];
s1[j][1] = s1[j+1][1];
s1[j+1][0] = temp1;
s1[j+1][1] = temp2;
}
}
}
for( i = 0 ; i < 10 ; i++ )
{
printf("No.%d: %.2f\n",(int)s1[i][0],s1[i][1]);
}
}
int main()
{
int arr[10][6] = { 0 };
int i = 0;
int j = 0;
char arr1 = '\0';
for( i = 0 ; i < 10 ; i++ )
{
for( j = 0 ; j < 6 ; j++ )
{
scanf("%c",&arr1);
getchar();
if( (int)arr1 <= (int)'9' && (int)arr1 >= (int)'0' )
{
arr[i][j] = (int)arr1 - (int)'0';
}
else
{
printf("成绩必须为十分制:\n");
return 0;
}
}
}
rank(arr);
return 0;
}
这篇关于歌唱比赛计分 (8 分)设有10名歌手(编号为1-10)参加歌咏比赛的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!