D-Gj

Povtoruvanje na site znaci

Mar 3rd, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. // Da se odredi kolku pati se povtoruva sekoj znak vo nekoja tekstualna niza.
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     char text[500], checked[500];
  10.     int checked_n = 0;
  11.  
  12.     cout << "Vnesi tekst: ";
  13.     cin.getline(text, 500);
  14.     cout << endl;
  15.  
  16.     for (int i = 0; text[i] != '\0'; ++i)
  17.     {
  18.         if (text[i] == ' ') continue;
  19.  
  20.         bool is_checked = false;
  21.  
  22.         for (int j = 0; text[j] != '\0'; ++j)
  23.         {
  24.             if (text[i] == checked[j])
  25.             {
  26.                 is_checked = true;
  27.             }
  28.         }
  29.  
  30.         if (is_checked) continue;
  31.  
  32.         char checking = text[i];
  33.         int n = 0;
  34.         checked[checked_n++] = checking;
  35.  
  36.         for (int j = 0; text[j] != '\0'; ++j)
  37.         {
  38.             if (text[j] == checking) n++;
  39.         }
  40.  
  41.         cout << "Znakot \"" << checking << "\" se povtoruva " << n << " pati." << endl;
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment