2 条题解

  • 0
    @ 2025-10-13 21:14:05

    奖励关

    循环遍历,找就完了

    参考代码(python)

    from sys import stdin,setrecursionlimit
    from math import inf,ceil,sqrt
    from collections import Counter,deque
    
    n,x=[int(_) for _ in stdin.readline().split()]
    a=[int(_) for _ in stdin.readline().split()]
    for i in range(n):
        if a[i]==x:
            print(i+1)
            exit()
    print(-1)
    
    
    • 0
      @ 2025-10-13 16:39:18

      出题人在比赛现场临时出的一道题,考察对数组的基本操作,当然也可以不用数组:

      #include <bits/stdc++.h>
      using namespace std;
      
      int main() {
          int n, x;
          cin >> n >> x;
          for (int i = 1, a; i <= n; i++) {
              cin >> a;
              if (a == x) {
                  cout << i << "\n";
                  return 0; // 很多初学者以为 return 0; 只能写在最后
              }
          }
          cout << "-1\n";
          return 0;
      }
      
      • 1

      信息

      ID
      1096
      时间
      1000ms
      内存
      256MiB
      难度
      6
      标签
      递交数
      94
      已通过
      29
      上传者