Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int getindexFromChar (char d) {
- int w = -1;
- if ( d >= 'A' && d <= 'Z' )
- w = d - 65;
- return w;
- }
- int main()
- {
- int index[256] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
- int frequency[256] { };
- char stroka[100];
- cout << "Vvedite stroku: ";
- cin.getline(stroka, 100);
- char k = ' ';
- int z = 0;
- int d = 0;
- while(stroka[d]) {
- k = stroka[d];
- if ( k >= 'a' && k <= 'z')
- k -= 32;
- frequency[getindexFromChar(k)]++;
- d++;
- }
- int length = 26;
- for(int i = 0; i < length - 1; i++){
- for(int n = 0; n < length - i - 1; n++) {
- if(frequency[index[n]] < frequency[index[n+1]]) {
- char d = index[n];
- index[n] = index[n+1];
- index[n+1] = d;
- }
- }
- }
- int c = 0;
- while(frequency[index[c]]) {
- char f = index[c]+65;
- cout << f << " - " << frequency[index[c]];
- cout<<endl;
- c++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement