元代青花釉里红拍卖:自己写的小程序,过不去,请大家指教

来源:百度文库 编辑:高考问答 时间:2024/04/30 00:40:54
虽然很难,不过是自己写的,以后或许能用上,下面是代码,看谁能帮我解释一下,哪里有问题(我用的是VC6.0)

#include <iostream.h>
#include <iomanip.h>

int main()
{
const int arraysize=20; //arraysize表示学生的人数
int m[arraysize]; //m[arraysize]用来乘放学生的成绩
int hold; //交换变量
int classes=5; //classes表示班级的数目
int i;
int a[4] = {0};
int b[4] = {0};
int c[4] = {0};
int d[4] = {0};
int e[4] = {0};

for ( int x=0; x<arraysize; x++ )
{
cout << "请输入学生的成绩:";
cin >> m[x];
}

for ( int pass=0; pass<arraysize-1; pass++ ) //冒泡排序排列学生成绩
for ( i=0; i<arraysize-1; i++ )
if ( m[i] > m[i+1] )
{
hold=m[i];
m[i]=m[i+1];
m[i+1]=hold;
}
cout << "以下是按成绩由低到高的排序,请核对\n";

for ( int r=0; r<arraysize; r++ )
cout << m[r] << setw(6);

cout << "\n下面开始进行分班工作\n";
cout << "学生总人数: " << arraysize << setw(8)
<< "班级数目: " << classes << setw(8)
<< "每班人数: " << arraysize/classes << endl;

for ( int h=0; h<4; h++ ) //蛇型分配方式将学生分班
{
if ( h % 2 !=0 )
{
a[ h ]=m[ 10h-1 ];
b[ h ]=m[ 10h-2 ];
c[ h ]=m[ 10h-3 ];
d[ h ]=m[ 10h-4 ];
e[ h ]=m[ 10h-5 ];
}
else
{
a[ h ]=m[ 5h+0 ];
b[ h ]=m[ 5h+1 ];
c[ h ]=m[ 5h+2 ];
d[ h ]=m[ 5h+3 ];
e[ h ]=m[ 5h+4 ];
}
}

return 0;
}

for ( int pass=0; pass<arraysize-1; pass++ ) //冒泡排序排列学生成绩
for ( int pass=0; pass<arraysize; pass++ )

你的错误都在蛇型分配上了

粗看一下,冒泡排序算法有问题。pass和i都是从0到arraysize循环,明显不正确。