转载华为测试题目
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");
}
#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");
}
相关文章推荐
- Algorithms—263.Ugly Number
- HDU 2674 N!mod2009
- C# 生成时间戳
- Unity3D - 图形性能优化
- Bag of Words(BOW)模型
- [LeedCode OJ]#190 Reverse Bits
- 面试题8
- jquery/js实现验证聚焦,失焦
- KindeEditor图片上传插件用法
- 直方图法、Kn近邻估计法、Parzen窗法
- PHP实现微信发红包程序
- Android IM(一)实现用户注册、登录、修改密码和注销
- 解决 VS2005解决方案下无法添加多个项目的问题
- 给出double底数求int的次方的递归和循环方法
- 在jsp页面上直接打开PDF文件
- 遍历Map的两种方法:keySet()和entrySet()
- C语言中对字母进行大小写转换的简单方法
- 下拉框,复选框
- Android-Fragment(与Activity 直接传参 / 通信)
- webchat