konchin_shih

paragraph analyzer

May 23rd, 2021 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<array>
  4. #include<cctype>
  5. #include<algorithm>
  6. using namespace std;
  7. using node=pair<char,long long>;
  8. int main(){
  9.     fstream fin("input.txt",ios::in);
  10.     fstream fout("output.txt",ios::out);
  11.     cin.rdbuf(fin.rdbuf());
  12.     cout.rdbuf(fout.rdbuf());
  13.     array<node, 26> table;
  14.     string str;
  15.     for(int i=0;i!=26;i++)
  16.         table[i].first='a'+i;
  17.     while(getline(cin,str))
  18.         for(const auto& i:str)
  19.             if(isalpha(i))
  20.                 table[i-'a'].second++;
  21.     sort(table.begin(),table.end(),[](node a,node b){
  22.         return a.second>b.second||(a.second==b.second&&a.first<b.first);
  23.     });
  24.     for(const auto& i:table)
  25.         cout<<i.first<<","<<i.second<<endl;
  26.     return 0;
  27. }
Add Comment
Please, Sign In to add comment