Advertisement
zamcsaba

BME Prog1 Szorgalmi 5

Oct 8th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <memory.h>
  6. #include <ctype.h>
  7.  
  8. void shuffle(char *word) {
  9.     bool last_alpha_passed = false;
  10.  
  11.     for (int i = strlen(word) - 1; i > 1; i--) {
  12.         if (!isalpha(word[i])) continue;
  13.  
  14.         if (!last_alpha_passed) {
  15.             last_alpha_passed = true;
  16.             continue;
  17.         }
  18.  
  19.         int r = rand() % i + 1;
  20.         char tmp = word[r];
  21.         word[r] = word[i];
  22.         word[i] = tmp;
  23.     }
  24. }
  25.  
  26. int main() {
  27.     srand(time(NULL));
  28.  
  29.     char actual_word[51];
  30.  
  31.     while (scanf("%s", actual_word) != EOF) {
  32.         shuffle(actual_word);
  33.         printf("%s ", actual_word);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement