arr11

Xem PDF



Tác giả:
Dạng bài
Điểm: 100 (p) Thời gian: 1.0s Bộ nhớ: 1023M Input: bàn phím Output: màn hình

Cho một dãy gồm n số nguyên dương \(A_1, A_2,…, A_n\). (\(N \le 10^5, A_i \le 10^9\)) và số \(x\). Hãy đếm số lần xuất hiện của giá trị \(x\) trong mảng \(A\).

Input

  • Dòng đầu chứa số \(n\)\(x\)
  • Dòng thứ hai chứa \(n\) số nguyên dương \(A_1, A_2,…, A_n\).

Output

  • Số lần xuất hiện số x trong mảng \(A\).

Example

Test 1

Input
6 451
91 451 43 3 451 54
Output
2

Bình luận

  • quocvinh1252012 11:45 a.m. 16 Tháng 3, 2025 chỉnh sửa 4

    include <bits/stdc++.h>

    using namespace std;

    const int maxn=1e5+5;
    int n, x, kq=0;
    int a[maxn];

    int main() {
    cin >> n >> x;
    for (int i=1; i<=n; i++) cin >> a[i];
    while (n--) {
    if (a[n]==x) kq++;
    }
    cout << kq;
    return 0;
    }

    • p12b511 6:54 p.m. 19 Tháng 12, 2024

      n,x=map(int,input().split())
      a=list(map(int,input().split()))
      dem=0
      for i in range(0,n):
      if a[i]==x:
      dem=dem+1
      print(dem)

      • quylam24012011 8:43 a.m. 25 Tháng 7, 2024

        ai cần code thì nhắn tin nha

        • PhucDepZai 7:36 p.m. 10 Tháng 6, 2024

          n,x=map(int,input().split())
          s=list(map(int,input().split()))
          a=s.count(x)
          print(a)

          • PhucDepZai 7:35 p.m. 10 Tháng 6, 2024 đã chỉnh sửa

            de ott

            • lhbmt 8:35 p.m. 7 Tháng 4, 2024

              include <bits/stdc++.h>

              using namespace std;
              int main()
              {
              long long N,x,dem=0;
              cin>>N>>x;
              long long A[N];
              for(int i=0;i<=N-1;i++)
              {
              cin>>A[i];
              if(A[i]==x) dem++;
              }
              cout<<dem;
              return 0;
              }

              • HaiAnh2008 7:52 p.m. 24 Tháng 11, 2023

                ac`include<bits/stdc++.h>

                include<algorithm>

                using namespace std;

                define maxn 100001

                int n,a[maxn],x;
                int main()
                {
                ios::sync_with_stdio(0);
                cin.tie(0);
                cout.tie(0);
                cin>>n>>x;
                for (int i = 1; i < n+1; ++i)
                {
                cin>>a[i];
                }
                sort(a+1,a+n+1);
                auto it1=lower_bound(a+1,a+n+1,x);
                auto it2=upper_bound(a+1,a+n+1,x);
                cout<<it2-it1;
                return 0;
                }
                `

                • tester123 8:49 p.m. 8 Tháng 11, 2023

                  orz ai làm bài này bằng binary search

                  Mình biết mỗi cách if(a[i] == x) res++ thôi =)))

                  • NhatAnhLe 2:01 p.m. 27 Tháng 11, 2022

                    This comment is hidden due to too much negative feedback. Click here to view it.

                    • khieudung123np 7:58 p.m. 5 Tháng 10, 2022

                      This comment is hidden due to too much negative feedback. Click here to view it.