Advertisement
Kostiggig

Untitled

Mar 6th, 2023
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4. #include <cstddef>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.    
  12.     char src[256];
  13.     int lengthOfWords = 0;
  14.     char **words = NULL;
  15.     gets(src);
  16.  
  17.    
  18.     char *currWord = strtok(src, " ");
  19.  
  20.    
  21.     while(currWord != NULL) {
  22.         words = (char**) realloc(words, (lengthOfWords + 1) * sizeof(char*));
  23.  
  24.         int lengthOfCurrWord = strlen(currWord);
  25.         words[lengthOfWords] = (char*)malloc(lengthOfCurrWord * sizeof(char));
  26.         words[lengthOfWords] = currWord;
  27.         lengthOfWords++;
  28.         if (currWord != NULL) {
  29.             currWord = strtok(NULL, " ");
  30.         }
  31.     }
  32.  
  33.     char result[256];
  34.    
  35.     for(int i = 0; i < lengthOfWords; i++) {
  36.         int counterUniqueChars = 0;
  37.         bool seen[26];
  38.  
  39.         for(int i = 0; i < 26; i++) seen[i] = false;
  40.  
  41.         int lengthOfCurrWord = strlen(words[i]);
  42.         for(int j = 0; j < lengthOfCurrWord; j++) {
  43.             const int symbol = (int) words[i][j];
  44.  
  45.             int indexOfChar = (symbol % 124) - 97;
  46.             if(seen[indexOfChar] == false) {
  47.                 seen[indexOfChar] = true;
  48.                 counterUniqueChars++;
  49.             }
  50.         }
  51.  
  52.         if(counterUniqueChars > 2) {
  53.             strcat(result, words[i]);
  54.             strcat(result, " ");
  55.         }
  56.     }
  57.  
  58.     cout << "Result stinfg is: ";
  59.     cout << result;
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement