[Mảng 1 Chiều Cơ Bản]. Bài 4. Lớn hơn, nhỏ hơn

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Author:
Problem source:
28Tech
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Cho mảng số nguyên A[] gồm N phần tử và số nguyên X , hãy đếm xem trong mảng có bao nhiêu số lớn hơn X và bao nhiêu số nhỏ hơn X.


Đầu vào

Dòng đầu tiên là số nguyên dương N

Dòng thứ 2 gồm N số nguyên viết cách nhau một vài khoảng trắng

Dòng thứ 3 là số nguyên X


Giới hạn

1<=N<=1000

-10^3<=A[i]<=10^3


Đầu ra

Dòng 1 in ra các số nhỏ hớn X, dòng 2 in ra các số lớn hơn X


Ví dụ :

Input 01
5
-798 183 434 850 555 
135
Output 01
1
4

Comments

Please read the guidelines before commenting.



  • 0
    Pqvinh07072015555  commented on May 7, 2025, 3:47 p.m. edited

    code python: enter image description here


  • -6
    thanhnay29  commented on Feb. 13, 2025, 7:38 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • 0
    nguyen_luong_an  commented on Dec. 18, 2024, 2:27 p.m.

    <3


  • -3
    mango_K  commented on Dec. 3, 2024, 3:12 p.m.

    bài này sai ở đâu ko mn,sao đúng đc 23 test vậy,

    include <bits/stdc++.h>

    using namespace std; int main() { int d1=0,d2=0; int n,x; cin>>n; int a[n]; for(int i=0;i<n;i++) cin >> a[i]; cin>>x; for(int i=0;i<n;i++){ if (a[i]<x) d1++; else if(a[i>x]) d2++; } cout<<d1<


    • 1
      bengokyeuanh99  commented on April 18, 2025, 6:17 a.m.

      Lỗi logic cực nặng:

      else if(a[i > x]) d2++;

      i > x là biểu thức so sánh, trả về true (1) hoặc false (0)

      a[i > x] tương đương a[1] hoặc a[0] tức là bạn đang truy cập sai phần tử mảng, không phải so sánh a[i] > x

      In ra kết quả bị thiếu hoặc lỗi cú pháp:

      cout<<d1<

      Thiếu phần còn lại (<< và d2) compiler báo lỗi syntax, hoặc in không đủ kết quả sai output lỗi này dễ gặp khi viết nhanh, không check kỹ output

      Dùng mảng kiểu C:

      int a[n];

      Với n <= 1000 thì có thể chạy được, nhưng về mặt kỹ thuật: đây là VLA (Variable Length Array) không chuẩn C++, một số compiler không hỗ trợ

      dùng vector<int> a(n); an toàn, sạch, dễ bảo trì


  • -3
    ngocshintran  commented on Nov. 6, 2024, 10:49 a.m.

    CODE

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main() {
      int n,x;
      cin >> n;
      vector<int> a(n);
      for (int &x : a) cin >> x;
      cin >> x;
      int min = 0, max = 0;
      for (int it : a) {
        if (it > x) max++;
        else if (it < x) min++;
      }
      cout << min << endl << max;
      return 0;
    }
    

  • -2
    Coder  commented on Sept. 26, 2024, 1:31 a.m.
    #include <iostream>

    using namespace std;

    int main() { int arr[10001]; int n; cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    
    int x; 
    cin >> x;
    
    int min = 0; 
    int max = 0; 
    
    for(int i = 0; i < n; i++) {
        if(arr[i] < x) {
            min++;
        } else if(arr[i] > x) {
            max++;
        }
    }
    
    cout << min << endl;  
    cout << max;
    
    return 0;
    

    }


  • -8
    duy210  commented on Aug. 26, 2024, 5:37 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -10
    theguy777_jaboi  commented on July 26, 2024, 8:33 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -6
    dangkhoa2836  commented on July 25, 2024, 3:06 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -13
    bynk2311  commented on June 9, 2024, 10:11 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.