[C] 纯文本查看 复制代码
#include<bits/stdc++.h>//头文件缺少time.h
using namespace std;
int a[1000],b[20000],temp=0,j,n,m;//b数组小了
int main()
{
srand(time(0));
cin>>n>>m;
for(int i=0;i<m;i++)
{
b[i]=rand();//对b数组赋值时应该写b[i],而且应该控制随机数的大小,不能超过参选人数n[/i]
[i] cout<<b[i];
cout<<endl;
}
for(int i=0;i<m;i++)
{
temp=i;
for(j=i+1;j<m;j++)
{
if(a[temp]>a[j])
{
temp=j;
}
}
swap(a[i],a[temp]);
}
for(int i=0;i<10;i++)//这里是要输出什么,参选人数的选票统计吗,那循环的上限是参选人数
{
cout<<a[i]<<" ";//输出这里应该是a[i]
}
}
|