[Mảng 1 Chiều Cơ Bản]. Bài 40. Số lần xuất hiện của chữ số

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 A[] gồm N phần tử, bạn hãy tách từng chữ số của các số trong mảng A[] và đếm xem mỗi chữ số xuất hiện bao nhiêu lần. Chú ý trong mảng A[] có thể có số âm


Đầu vào

Dòng 1 là N : số phần tử trong mảng

Dòng 2 là N số trong mảng viết cách nhau 1 dấu cách


Giới hạn

1<=N<=10^6

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


Đầu ra

• In ra các chữ số xuất hiện trong các số ban đầu trong mảng theo thứ tự tăng dần kèm theo số lần xuất hiện của chúng


Ví dụ :

Input 01
15
-3097 3584 4443 2088 1173 4029 5756 1436 4038 8538 -2054 2890 2376 3745 2684
Output 01
0 6
1 3
2 6
3 9
4 10
5 6
6 4
7 5
8 8
9 3

Comments

Please read the guidelines before commenting.



  • -2
    VDev  commented on Jan. 18, 2025, 5:47 a.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] = {0}, s = 0, mark[10000011];
    
    int main(){
        ll n;
        cin >> n;
        for(ll i = 0; i < n; i++){
            cin >> a[i];
            a[i] = abs(a[i]);
                    while(a[i] > 0){
                    cnt[a[i] % 10]++;
                    a[i] /= 10;
                }
        }
        for(ll i = 0; i < n; i++){
            if(cnt[i]){
                cout << i << " " << cnt[i] << endl;
            }
        }
        return 0;
    }
    

  • -6
    khuemih  commented on Oct. 30, 2024, 12:23 a.m.

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


  • -7
    vqhuy18  commented on June 24, 2024, 6:49 a.m.

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


  • -10
    MinhKhanh  commented on April 2, 2024, 11:24 a.m.

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


  • -7
    MinhKhanh  commented on April 2, 2024, 11:23 a.m.

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