(算法练习)——查找

要求:
http://codeup.cn/problem.php?cid=100000585&pid=2
说明:
这一题也是用的暴力= =内层循环要用个break,这样避免给的数组有重复的时候,重复输出YES;而且加了break系统才给通过

#include <stdio.h>
#include <string.h>

int main(){
	int n,m;
	int numrecord[110];
	int ansrecord[110];
	while(scanf("%d",&n) != EOF){
		for(int i = 0;i <n;i++){
			scanf("%d",&numrecord[i]);
		}
		scanf("%d",&m);
		for(int j = 0;j <m;j++){
			scanf("%d",&ansrecord[j]);
		}
		
		for(int i =0;i <m;i++){
			int flag = 0;
			for(int j = 0;j <n;j++){
				if(ansrecord[i] == numrecord[j]){
					printf("YES\n");
					flag = 1;
					//此处务必有break 
					break;	
				}	
			}
			if(flag == 0){
				printf("NO\n");
			}
		}
		memset(numrecord,0,sizeof(numrecord));
		memset(ansrecord,0,sizeof(ansrecord));
	}
}
发布了105 篇原创文章 · 获赞 3 · 访问量 1956

猜你喜欢

转载自blog.csdn.net/weixin_42377217/article/details/104027044