您的位置:首页 > 其它

转载华为测试题目

2015-08-24 14:55 288 查看
要求如下


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 30000
#define M 500

struct student{
int num ;
int score;
};

//寻找结构体min-max最高分
int sort(struct student stu[], int min, int max)
{
int i,maxscore;
for(i=min;i<max;i++)
{
maxscore=stu[min].score;
if(maxscore<stu[i].score)
maxscore=stu[i].score;

}

return maxscore;

}

int fresh(struct student stu[],int a,int b)
{
stu[a].score=stu[b].score;
return stu[a].score;
}

int main(void)
{
//m代表学生数目,n代表操作数目
int m,n,l,w;

char s;
int i,scot,max;
printf("please input m:nums of stu and n:nums of opetations\n");
scanf("%d %d",&m,&n);
struct student a
;

//初始化学生结构体
for(i=0;i<m;i++)
{
scanf("%d",&scot);
a[i].num=i;
a[i].score=scot;

}
printf("\n");

//循环操作次数
for(i=0;i<n;i++)
{
printf("please input Q/U l:stu L-stuW\n");
scanf("%s %d %d",&s,&l,&w);
if(s=='Q')
{
max=sort(a,l,w);
printf("max=%d\n",max);
}

else if(s=='U')
a[l].score=fresh(a,l,w);

printf("a[l].score=%d\n",a[l].score);

}
printf("\n");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: