fork download
  1. #include<iostream>
  2.  
  3. int main(void) {
  4. using namespace std;
  5.  
  6. char c;
  7. int cnt[10] = { 0 }; //配列cntの全要素を0で初期化
  8.  
  9. while (cin.get(c)) {
  10. if (c >= '0' && c <= '9')
  11. cnt[c - '0']++;
  12. }
  13. for (int i = 0; i < 10; i++)
  14. cout << i << "の出現回数:" << cnt[i] << '\n';
  15.  
  16. getchar();
  17. cin.ignore();
  18. return(0);
  19. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
0の出現回数:0
1の出現回数:0
2の出現回数:0
3の出現回数:0
4の出現回数:0
5の出現回数:0
6の出現回数:0
7の出現回数:0
8の出現回数:0
9の出現回数:0