pat各位数统计

  1. #include <iostream>  
  2. #include <string>  
  3. #include <algorithm>  
  4. using namespace std;  
  5.   
  6. int a[10]={0};  
  7. string s;  
  8.   
  9. int main()  
  10. {  
  11.     cin>>s;  
  12.     int i;  
  13.   
  14.     for(i = 0; i < s.length(); ++i)  
  15.         a[s[i]-'0']++;  
  16.     for(i = 0; i < 10; ++i)  
  17.         if(a[i] != 0)  
  18.             cout<<i<<":"<<a[i]<<endl;  
  19.     return 0;  
  20. }  
posted @ 2016-09-04 07:56  code666  阅读(112)  评论(0编辑  收藏  举报