[Mảng 1 Chiều Cơ Bản]. Bài 3. Số nhỏ nhất

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ử, hãy đếm xem trong mảng của bạn có bao nhiêu số có cùng giá trị nhỏ nhất. Ví dụ mảng A = {1, 2, 1, 3, 5} thì số nhỏ nhất trong mảng là 1 xuất hiện 2 lần.


Đầ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


Giới hạn

1<=N<=1000

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


Đầu ra

In ra đáp án của bài toán


Ví dụ :

Input 01
5
-854 600 222 472 207
Output 01
1
Input 02
5
28 28 28 28 29
Output 02
4

Comments

Please read the guidelines before commenting.



  • 0
    bengokyeuanh99  commented on April 10, 2025, 3:36 a.m.

    import sys

    def countminoccurrences(arr): if not arr: return 0

    min_val = min(arr)
    return arr.count(min_val)
    

    def parse_input(): try: n = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline().split())) if len(arr) != n: raise ValueError("Số lượng phần tử không khớp") return arr except Exception as e: print("Input không hợp lệ:", e) sys.exit(1)

    def main(): arr = parseinput() result = countmin_occurrences(arr) print(result)

    if name == "main": main()


  • 0
    duc_thanh_0111  commented on April 9, 2025, 6:06 p.m.

    int n; cin >> n;

    vector<int> a(n);
    
    for (int i=0; i&lt;n; i++) {
        cin >> a[i];
    }
    
    int count = 1;
    int init_idx = 0;
    
    for (int i = 1; i < n; i++) {
        if (a[init_idx] > a[i]) {
            init_idx = i;
            count = 1;
        } else if (a[init_idx] == a[i]) {
            count ++;
        }
    }
    cout << count;
    

  • -3
    thanhnay29  commented on Feb. 8, 2025, 9:34 a.m.

    buon cuoi vai


    • 1
      BaoHuangg  commented on March 12, 2025, 8:35 a.m.

      code thieu nhi thi y kien gi


  • -2
    cocomelon_0202  commented on Jan. 14, 2025, 9:53 a.m.

    include <bits/stdc++.h>

    using namespace std;

    define rw(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)

    define ll long long

    define el "\n"

    define ios iosbase::syncwith_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    const ll maxn=1e7;

    ll x,n, minn;

    int main() { ios; rw("test");

    cin>>n;
    
    map<ll,ll> mp;
    minn=LLONG_MAX;
    for (ll i=1; i<=n; i++) cin>>x, mp[x]++, minn=min(minn, x);
    
    cout<&lt;mp[minn];
    
    
    
    return (0^0);
    

    }


  • -3
    Bondy002008  commented on Sept. 16, 2024, 6:36 a.m.

    include<bits/stdc++.h>

    using namespace std;

    int main() { int n,j=0,d=1; cin>>n; int a[n]; for (int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); for (int i=0;i<n;i++){ if (a[i]==a[i+1])d++; else break; } cout<<d; } Code tui như này nè


  • -4
    Zzbopro123Zz  commented on July 13, 2024, 3:24 p.m.

    include <bits/stdc++.h>

    using namespace std; int findmin(const vector<int> &arr) { int minvalue = numericlimits<int>::max(); for (int num : arr) { if (num < minvalue) { minvalue = num; } } return minvalue; } int main() { iosbase::syncwithstdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; ++i) { cin >> arr[i]; } int minvalue = findmin(arr); int count = 0; for (int i = 0; i < n; i++) { if (arr[i] == minvalue) { count++; } } cout << count << endl; return 0; } code của tui kiểu :< sao có thể ngắn như mn được nhỉ


  • -3
    PhamBaDat_k5  commented on May 25, 2024, 3:35 a.m.

    include <bits/stdc++.h>

    using namespace std; int main() { int n; cin >> n; int a[3000]; for (int i = 0; i < n; i++) { cin >> a[i]; } int cnt = 0; int res = INT_MAX; for (int i = 0; i < n; i++) { if (a[i] < res) { cnt = 0; res = a[i]; } if (a[i] == res) { cnt++; } } cout << cnt <<endl;

    return 0;
    

    }

    Code tui như này .-.


  • -6
    NTH11112222  commented on May 25, 2024, 2:58 a.m.

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


  • -2
    long_674  commented on May 10, 2024, 6:58 a.m.

    ai xem giups bai minh sai gif khong,testcase dung 30/31


    • -3
      Malaze_KL  commented on June 4, 2024, 6:17 a.m.

      min = -10000 ông bỏ dấu trừ đi; if(a[i]<=min) min=a[i]; mới đúng nhé


    • -3
      Malaze_KL  commented on June 4, 2024, 6:00 a.m.

      hmm