Advertisement
Taraxacum

Characters Statistics

Oct 28th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(int argc, char const* argv[])
  6. {
  7.     int stat[256]{ 0 };
  8.     char ch;
  9.  
  10.     while (cin.get(ch) && ch != '@') {
  11.         stat[unsigned(ch)]++;
  12.     }
  13.  
  14.     int alpha = 0;
  15.     int numeric = 0;
  16.     int others = 0;
  17.  
  18.     cout << "\n--- stat ---" << endl;
  19.  
  20.     for (unsigned ch = 0; ch < 256; ch++) {
  21.         if (ch >= 'A' && ch <= 'Z') {
  22.             alpha += stat[ch];
  23.         } else if (ch >= 'a' && ch <= 'z') {
  24.             alpha += stat[ch];
  25.         } else if (ch >= '0' && ch <= '9') {
  26.             numeric += stat[ch];
  27.         } else {
  28.             others += stat[ch];
  29.         }
  30.     }
  31.  
  32.     cout << "alpha\t" << alpha << endl
  33.          << "numeric\t" << numeric << endl
  34.          << "others\t" << others << endl;
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement