Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- char index[256];
- int frequency[256] { };
- char stroka[100];
- cout << "Vvedite stroku: ";
- cin.getline(stroka, 100);
- char k = ' ';
- int z = 0;
- while ( k != 0) {
- k = stroka[z];
- if ( k >= 'a' && k <= 'z') {
- stroka[z] -= 32;
- }
- z++;
- }
- int d = 0;
- while(stroka[d]) {
- index[stroka[d]-65] = stroka[d];
- frequency[stroka[d]-65]++;
- d++;
- }
- int length = 26;
- for(int i = 0; i < length - 1; i++){
- for(int n = 0; n < length - i - 1; n++) {
- if(frequency[n] < frequency[n+1]) {
- int b = frequency[n];
- frequency[n] = frequency[n+1];
- frequency[n+1] = b;
- char d = index[n];
- index[n] = index[n+1];
- index[n+1] = d;
- }
- }
- }
- int c = 0;
- while(frequency[c]) {
- cout << index[c] << " - " << frequency[c];
- cout << endl;
- c++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement