Advertisement
huutho_96

normalize

Dec 25th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. //https://www.facebook.com/CungHocLapTrinhUIT/
  2. #include <stdio.h>
  3.  
  4. void strNormal(char *str)
  5. {
  6.     int j = 0;
  7.     for (int i = 0; str[i] != 0; i++)
  8.     {
  9.         if (str[i] != ' ')
  10.         {
  11.             if (str[i - 1] == ' ')
  12.             {
  13.                 if (str[i] > 96 && str[i] < 123)
  14.                     str[j++] = str[i] - 32;
  15.                 else
  16.                     str[j++] = str[i];
  17.             }
  18.             else
  19.             {
  20.                 if (str[i] > 64 && str[i] < 91)
  21.                     str[j++] = str[i] + 32;
  22.                 else
  23.                     str[j++] = str[i];
  24.             }
  25.         }
  26.         else
  27.         {
  28.             if (i != 0 && str[i - 1] != ' ')
  29.             {
  30.                 str[j++] = str[i];
  31.             }
  32.         }
  33.     }
  34.     str[0] = (str[0] > 96 ? str[0] - 32 : str[0]);
  35.     str[j] = 0;
  36. }
  37.  
  38. void main()
  39. {
  40.     char str[1024];
  41.     gets(str);
  42.     strNormal(str);
  43.     puts(str);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement