题解 | #找x#

找x

https://www.nowcoder.com/practice/069e2130430c41229ab25e47fa0949a6

#include "stdio.h"
#include "algorithm"
using namespace std;

int main(){
    int n;
    int num[200];
    int x,flag=-1;
    while (scanf("%d",&n)!=EOF){
        flag=-1;
        for (int i = 0; i < n; ++i) {
            scanf("%d",&num[i]);
        }
        scanf("%d",&x);
        for (int i = 0; i < n; ++i) {
            if(num[i]==x){
                flag=i;
                break;
            }
        }
        printf("%d\n",flag);
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务