Guest User

10062

a guest
Oct 21st, 2018
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<fstream>
  4. using namespace std;
  5.  
  6. typedef class data{
  7. public:
  8.     data(){
  9.         ascii=0;
  10.         time=0;
  11.     }
  12.     int ascii;
  13.     int time;
  14. private:
  15. }data;
  16. bool cmp(data a,data b){
  17.     if(a.time!=b.time)
  18.         return a.time<b.time;
  19.     else
  20.         return a.ascii>b.ascii;
  21. }
  22. int main()
  23. {
  24.     char str[1000];
  25.     bool first=true;
  26.     while(fgets(str,sizeof(str),stdin)){
  27.         data D[128];
  28.         int sum[129]={0};
  29.         int cnt=0;
  30.         if(first!=true)
  31.             cout<<endl;
  32.         first=false;
  33.         for(int i=0;str[i];++i){
  34.             ++sum[(int)str[i]];
  35.         }
  36.         for(int i=32;i<128;++i){
  37.             if(sum[i]!=0){
  38.                 D[cnt].ascii=i;
  39.                 D[cnt].time=sum[i];
  40.                 ++cnt;
  41.             }
  42.         }
  43.         sort(D,D+cnt,cmp);
  44.         for(int i=0;i<cnt;i++){
  45.             cout<<D[i].ascii<<" "<<D[i].time<<endl;
  46.         }
  47.     }
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment