码迷,mamicode.com
首页 > 其他好文 > 详细

直方图

时间:2018-03-06 23:18:35      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:else   ring   string   柱状图   ret   gpo   pac   pos   names   

 1 #include <iostream>
 2 #include <string>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 int main(){
 7     string a;
 8     while (cin >> a){
 9         int i, j, max = 0, num[10] = { 0 };
10         for (i = 0; i<a.length(); i++) 
11             num[a[i] - 0]++;
12         for (i = 0; i<10; i++)
13         if (num[i]>max)
14             max = num[i]; //找到最大次数,即柱状图层数
15         for (i = max; i>0; i--){ 
16             for (j = 0; j<10; j++){ 
17                 if (i>num[j])
18                     cout <<  ; else cout << *;
19             }
20             cout << endl;
21         }
22         cout << "0123456789" << endl; //标出横轴
23     }
24     return 0;
25 }

 

直方图

标签:else   ring   string   柱状图   ret   gpo   pac   pos   names   

原文地址:https://www.cnblogs.com/jaydenouyang/p/8516871.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!