document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <iostream>
  2. #include <string>
  3. #include <list>
  4. using namespace std;
  5.  
  6. struct Word
  7. {
  8.     char ch;
  9.     int count;
  10. };
  11.  
  12. bool wordCompare(Word w1, Word w2)
  13. {
  14.     if(w1.count>w2.count){
  15.         return true;
  16.     }
  17.     else if(w1.count<w2.count){
  18.         return false;
  19.     }
  20.     else if(w1.ch<w2.ch){
  21.         return true;
  22.     }
  23.     else{
  24.         return false;
  25.     }
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31.     int N;
  32.     list<Word> wordList;
  33.     struct Word w[26];
  34.     int a[26]={0};
  35.     string str;
  36.     cin>>N;
  37.     getline(cin,str);
  38.  
  39.     for(int i=0;i<N;i++){
  40.         getline(cin,str);
  41.         for(int j=0; j<str.length() ;j++){
  42.             if( isalpha(str[j]) ){
  43.                 int chInt = toupper(str[j])-\'A\';
  44.                 a[ chInt ]++;
  45.             }
  46.         }
  47.     }
  48.    
  49.     for(int i=0;i<26;i++){
  50.         if(a[i]>0){
  51.             //Word a = new Word;若改成臨時加不知道行不行?
  52.             w[i].ch = (char) (i+\'A\');
  53.             w[i].count=a[i];
  54.             wordList.push_front(w[i]);
  55.         }
  56.     }
  57.  
  58.     wordList.sort(wordCompare);
  59.  
  60.     list<Word>::iterator it;
  61.     for ( it=wordList.begin() ; it != wordList.end(); it++ ){
  62.         if((*it).count>0){
  63.             cout <<(*it).ch<<" "<<(*it).count<<endl;
  64.         }
  65.     }
  66.  
  67.     return 0;
  68. }
');