Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct letter{
- char letter;
- int count;
- };
- int main()
- {
- string str;
- struct letter alph[28];
- for(int i = 0; i < 26; i++)
- alph[i].count = 0;
- char c = 'a';
- for(int i = 0; i < 26; i++)
- alph[i].letter = c + i;
- while (1)
- {
- getline(cin, str);
- // cout << str << endl;
- if (str[0] == '*')
- break;
- for (int j = 0; j < str.length(); j++)
- {
- while (str[j] != 0 && str[j] == ' ')
- j++;
- alph[str[j] - 97].count++;
- while (str[j] != 0 && str[j] != ' ')
- j++;
- }
- }
- struct letter temp;
- for(int i = 0; i < 26; i++)
- {
- for(int k = 0; k < 26 - i; k++)
- {
- if (alph[k + 1].count > alph[k].count )
- {
- temp = alph[k + 1];
- alph[k + 1] = alph[k];
- alph[k] = temp;
- }
- }
- }
- for(int i = 0; i < 26; i++)
- {
- if (alph[i].count != 0)
- {
- cout << alph[i].letter << ' ' << alph[i].count << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement