Advertisement
KropkaRobert

Untitled

Jan 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string riadok = "s simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
  9.     string riadokWithoutSpace;
  10.  
  11.     cout << "riadok: '" << riadok << "'" << endl;
  12.    
  13.     int count[256]; // <-- assuming char is 8 bytes
  14.     for (int i = 0; i != 256; ++i)
  15.     {
  16.         count[i] = 0; // <-- set all counts to be zero
  17.     }
  18.  
  19.     for (int i = 0; riadok[i] != '\0'; i++)
  20.     {
  21.         count[riadok[i]] = count[riadok[i]] + 1;
  22.  
  23.         if (riadok[i] != ' ')
  24.         {
  25.             riadokWithoutSpace += riadok[i];
  26.         }
  27.     }
  28.  
  29.     cout << endl << "Kilkist elementiw:" << endl;
  30.  
  31.     for (int i = 0; i != 256; ++i)
  32.     {
  33.         if (count[i] != 0)
  34.         {
  35.             char aChar = i;
  36.             if (i == 32)
  37.                 cout << count[i] << " x space" << endl;
  38.             else
  39.                 cout << count[i] << " x " << aChar << endl;
  40.         }
  41.     }
  42.        
  43.     cout << endl << "riadok bez spacji: '" << riadokWithoutSpace << "'" << endl;
  44.  
  45.     system("pause");
  46.     return(0);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement