首页 > 试题广场 >

查找

[编程题]查找
  • 热度指数:31706 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
输入数组长度 n 输入数组      a[1...n] 输入查找个数m 输入查找数字b[1...m]   输出 YES or NO  查找有则YES 否则NO 。

输入描述:
输入有多组数据。
每组输入n,然后输入n个整数,再输入m,然后再输入m个整数(1<=m,n<=100)。


输出描述:
如果在n个数组中输出YES否则输出NO。
示例1

输入

5
1 5 2 4 3
3
2 5 6

输出

YES
YES
NO
头像 潇尘
发表于 2021-03-18 17:13:09
使用map时间复杂度为O(m) #include <iostream> #include <map> using namespace std; int main() { int n; int m; while(cin>>n) { 展开全文
头像 帅呆呆~
发表于 2022-03-06 14:27:38
#include<cstdio> #include <algorithm> #include <string> #include <iostream> #include <cstring> using namespace std; con 展开全文
头像 牛牛客小菜
发表于 2021-08-21 12:41:46
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; bool Find(int a[],int n,int target){     in 展开全文
头像 asaboppfarr
发表于 2021-09-28 23:00:28
#include<iostream> #include<algorithm> using namespace std; int main(){ int n,m; while(cin>>n){ int a[n]; fo 展开全文
头像 渺小小螃蟹
发表于 2021-05-10 13:23:45
#include<stdio.h> #include<stdbool.h> const int max=100; int arr[max]; bool linearsearch(int n,int target) { for(int i=0;i<n;i++) 展开全文
头像 在考古的小鱼干很有气魄
发表于 2023-03-18 12:02:04
#include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; int main(){ int n,m,tmp; vector<int> a,b; cin>>n; for(int 展开全文
头像 无敌小发
发表于 2023-03-27 00:23:57
//输入数组长度 n 输入数组 a[1...n] 输入查找个数m 输入查找数字b[1...m] //输出 YES or NO 查找有则YES 否则NO 。 #include <stdio.h> #include <string.h> int main() { 展开全文
头像 Javker丶鑫
发表于 2021-03-19 12:37:18
前半段是用两个辅助数组存值后半段二分查找,找到后break返回,设置flag锁来定输出注意这里while()循环条件是left<right以及转移时是left=mid+1; .... right=mid; import java.util.Arrays; import java.util 展开全文
头像 yyer
发表于 2023-01-01 11:03:49
#include <iostream> #include <algorithm> using namespace std; int main() { int n,m; while(cin>>n){ int *A = (int*)mallo 展开全文
头像 帅呆呆~
发表于 2022-03-06 20:57:05
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int RANGE = 1e6; const 展开全文

问题信息

难度:
159条回答 11420浏览

热门推荐

通过挑战的用户

查看代码