数据结构上机实验之顺序查找

    xiaoxiao2025-03-06  5

    题目描述

     在一个的序列里,查找元素是否存在,若存在输出YES,不存在输出NO.

    输入

     本题多组数据,首先输入一个数字n,然后输入n(n<=1000)个数,然后再输入一个查找数字。

    输出

     若存在输出YES,不存在输出NO.

    示例输入

    4 1 3 5 8 3

    示例输出

    YES

    两个字-->水题

    <span style="font-size:18px;">#include <iostream> #include <cstdio> using namespace std; int main() { int n,i,x,a[10001],t; while(~scanf("%d",&n)) { t=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); } scanf("%d",&x); for(i=0;i<n;i++) { if(a[i]==x) t=1; } if(t==1) cout << "YES" << endl; else cout << "NO" << endl; } return 0; } </span>
    转载请注明原文地址: https://ju.6miu.com/read-1296950.html
    最新回复(0)