题目
本题要求实现一个函数,要求返回顺序表中大于指定元素值的个数,空表返回0。题目保证顺序表中所有元素都为整数。
函数接口定义:
int GetGreater(SqList L, ElemType e);
函数GetGreater返回顺序表L中比e大的元素的个数,若顺序表为空,则返回0。
其中SqList结构定义如下:
typedef struct
{
ElemType *elem;
int length;
}SqList;
```
### 裁判测试程序样例:
```c++
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
}SqList;
void InitList(SqList &L);/*细节在此不表*/
int GetGreater(SqList L, ElemType e);
int main()
{
SqList L;
InitList(L);
ElemType e;
scanf("%d", &e);
printf("The number greater than %d is %d.\n",e, GetGreater(L, e));
return 0;
}
/* 请在这里填写答案 */
输入格式:
输入数据有2行,第一行给出以-1结束的顺序表元素(不超过10000个,-1不属于顺序表元素),所有数据之间用空格分隔。题目保证输入的顺序元素都是整数。第二行给出要指定的元素值。
输出样例:
The number greater than 6 is 2.
代码:
int GetGreater(SqList L, ElemType e)
{
int count=0;
for(int i=0;i<L.length;i++)
{
if(L.elem[i]>e)
{
count++;
}
}
return count;
}