Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- #include<fstream>
- using namespace std;
- typedef class data{
- public:
- data(){
- ascii=0;
- time=0;
- }
- int ascii;
- int time;
- private:
- }data;
- bool cmp(data a,data b){
- if(a.time!=b.time)
- return a.time<b.time;
- else
- return a.ascii>b.ascii;
- }
- int main()
- {
- char str[1000];
- bool first=true;
- while(fgets(str,sizeof(str),stdin)){
- data D[128];
- int sum[129]={0};
- int cnt=0;
- if(first!=true)
- cout<<endl;
- first=false;
- for(int i=0;str[i];++i){
- ++sum[(int)str[i]];
- }
- for(int i=32;i<128;++i){
- if(sum[i]!=0){
- D[cnt].ascii=i;
- D[cnt].time=sum[i];
- ++cnt;
- }
- }
- sort(D,D+cnt,cmp);
- for(int i=0;i<cnt;i++){
- cout<<D[i].ascii<<" "<<D[i].time<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment