[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
    nguyen_luong_an  commented on Dec. 18, 2024, 2:27 p.m.

    <3


  • -1
    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<


  • 0
    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;
    }
    

  • -1
    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;
    

    }


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

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


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

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


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

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


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

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