Advertisement
danielvitor23

Contagem de Algarismos

Jun 24th, 2021
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // 12134
  5. // 12134 % 10 = 4
  6. // 12134/10 = 1213
  7.  
  8. int cont[10]; // Tudo zeros
  9.  
  10. int main() {
  11.     int n;
  12.     cin >> n;
  13.     int x, temp1;
  14.     for(int i=0;i<n;i++){
  15.         cin >> x;
  16.         if (x > 0) {
  17.             while(x >= 1){
  18.                 temp1 = x % 10;
  19.                 x = x / 10;
  20.                 cont[temp1]++;
  21.             }
  22.         } else {
  23.             cont[0]++;
  24.         }
  25.     }
  26.     for(int c=0;c<10;c++){
  27.         cout<<c<<" - "<<cont[c]<<endl;
  28.     }
  29.     return 0;
  30. }
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement