1722: 查找-顺序查找
金币值:2
定数:5
时间限制:1.000 s
内存限制:128 M
正确:6
提交:11
正确率:54.55% 命题人:
题目描述
采用顺序查找方式完成指定关键字查找,找到返回对应位置,未找到输出0
#include <stdio.h> #include <stdlib.h> #define MAXSIZE 100 typedef struct { int *R; int length; } SSTable; void init(SSTable &ST) { ST.R=(int *)malloc(MAXSIZE*sizeof(int)); if(!ST.R) exit(0); ST.length=0; } void input(SSTable &ST,int n); int Search_Seq(SSTable ST,int key); int main(void) { SSTable st; int n,key,index; init(st); scanf("%d",&n); input(st,n); scanf("%d",&key); index=Search_Seq(st,key); printf("%d",index); return 0; } /*以下为你的代码*/
输入格式
第1行:查找表中的元素个数n
第2行:n个元素
第3行:待查找的key
第2行:n个元素
第3行:待查找的key
输出格式
找到返回对应位置,未找到输出0
输入样例 复制
6
1 6 8 10 7 9
10
输出样例 复制
4