[Mảng 1 Chiều Cơ Bản]. Bài 27. Mảng đánh dấu 2

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 liệt kê các giá trị xuất hiện trong mảng theo thứ tự từ nhỏ đến lớn kèm theo tần suất của 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

  • 0<=A[i]<=10^6


Đầu ra
  • In ra nhiều dòng, mỗi dòng gồm giá trị và tần suất viết cách nhau một khoảng trắng

Ví dụ :

Input 01
6
6 6 4 6 0 8
Output 01
0 1
4 1
6 3
8 1

Comments

Please read the guidelines before commenting.



  • 0
    Lam_Thang2014  commented on July 31, 2026, 12:18 p.m.

    hehee

    include <iostream>

    include<climits>

    using namespace std;

    int n;

    int a,b[1111111],Max = INT_MIN;

    int main() {

    iosbase::syncwith_stdio(false);

    cin.tie(NULL);

    cin >> n;

    for(int i = 0; i < n; i++)

    {

      cin >> a;
    
     b[a]++;
    

    Max = max(Max,a);

    }

    //cout << Max << endl;

    for(int i = 0; i <= Max; i++)

    {

    if(b[i] > 0) cout << i << " " << b[i] << endl;
    

    }

    return 0;

    }


  • -2
    kietne  commented on Dec. 14, 2025, 12:52 p.m.

    CODE FULL AC CHO AE ĐÂY: #include <bits/stdc++.h> using namespace std; using ll = long long; int a[1000001] = {0}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // viết code ở đây int n; cin >> n; int b[n]; for (int &i : b) cin >> i; for (int i = 0; i < n; i++) { a[b[i]]++; } int index = *max_element(b, b + n); for (int i = 0; i < index + 1; i++) { if (a[i] != 0) { cout << i << " " << a[i] << "\n"; } } return 0; }


  • 0
    HoangHai  commented on Aug. 24, 2025, 1:51 p.m.

    FULL AC

    #include <iostream>
    #include<climits>
    using namespace std;
    int n;
    int a,b[1111111],Max = INT_MIN;
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin >> n;
        for(int i = 0; i < n; i++)
        {
            cin >> a;
            b[a]++;
            Max = max(Max,a);
        }
        //cout <<  Max << endl;
        for(int i = 0; i <= Max; i++)
        {
            if(b[i] > 0) cout << i << " " << b[i] << endl;
        }
        return 0;
    }
    

  • -11
    HAIDONGTHAP  commented on July 19, 2025, 8:12 a.m.

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


  • -2
    hngoc  commented on July 4, 2025, 3:33 p.m.
    n=input()
    a=input().split()
    b=[]
    for i in range(1000001):
        b.append(0)
    for x in a:
        b[int(x)]+=1
    for i in range(1000001):
        if b[i]:
            print(i, b[i])
    

  • -2
    minhtai208  commented on July 2, 2025, 8:17 a.m.

    include <iostream>

    include <iomanip>

    include <math.h >

    include <climits>

    using namespace std; int mark[1000005]; int a[1000005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int max = INT_MIN; for (int i = 0; i < n; i++) { mark[a[i]]++; if (a[i] > max) { max = a[i]; } } for (int i = 0; i <= max; i++) { if (mark[i]) { cout << i << " " << mark[i] << endl; } } return 0; }


  • -3
    bengokyeuanh99  commented on June 16, 2025, 6:51 p.m.

    include <iostream>

    using namespace std;

    const int N = 1000005; int freq[N] = {0};

    int main() { ios::syncwithstdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, x, max_val = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x;
        freq[x]++;
        if (x > max_val) max_val = x;
    }
    
    for (int i = 0; i <= max_val; i++) {
        if (freq[i]) cout << i << " " << freq[i] << '\n';
    }
    
    return 0;
    

    }


  • 0
    VDev  commented on Jan. 17, 2025, 3:23 p.m.

    FULL AC

    #include <bits/stdc++.h>
    #include <iomanip>
    #include <cmath>
    #include <climits>
    #define ll long long
    using namespace std;
    ll a[10000011];
    ll cnt[1000011], s = 0, res = INT_MIN;
    
    int main(){
        ll n;
        cin >> n;
        for(ll i = 1; i <= n; i++){
            cin >> a[i];
        }
        for(ll i = 1; i <= n; i++){
            cnt[a[i]]++;
            if(a[i] > res){
                res = a[i];
            }
        }
        for(ll i = 0; i <= res; i++){
            if(cnt[i]){
                cout << i << " " << cnt[i] << endl;
            }
        }
        return 0;
    }
    

    • 0
      tranhoang11111  commented on Jan. 22, 2025, 2:22 p.m.

      ông để ngta động não đi chứ :))


      • 0
        VDev  commented on Jan. 26, 2025, 5:05 p.m.

        ay da chợt nhận ra quen tay bố ròi, mà tui code ở c++11 mà ng ta dùng cái khác hay sao mà tui bị -5 đánh giá, hay là do tui nhét code nên downvote vì gửi code :))


  • -6
    VuxPerfect  commented on June 9, 2024, 3:00 a.m.

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


  • -13
    ken123  commented on May 16, 2024, 1:11 p.m.

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