您的位置:首页 > 其它

2016华为校招上机笔试练习题1

2015-11-10 03:02 405 查看


C++ Code
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

int main()

{

int m;

int n;

while(scanf("%d %d", &n,&m) != EOF)

{

printf("学生数为%d,操作数为%d\n", n, m);

int *score = (int*)malloc(sizeof(int)*n);

int res[5000];

int cnt = 0;

int i;

for(i = 0; i < n; i++)

{

printf("请输入第%d的成绩\n", i);

scanf("%d", &score[i]);

}

char t;

int a = 0;

int b = 0;

while(m--)

{

//scanf("%c", &t);

scanf("%c",&t);

if(t == '\n')

scanf("%c",&t);

scanf("%d %d", &a, &b);

if(t == 'Q')

{

int max = 0;

for(i = a; i <= b; i++)

{

if(score[i] > max)

{

max = score[i];

}

}

res[cnt++] = max;

}

else

score[a] = b;

}

for( i=0; i<cnt; i++)

printf("%d\n",res[i]);

free(score);

}

return 0;

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