Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. void russianCorrection(char* str)
  2. {
  3.  
  4.     for (int i = 0; i < (int)strlen(str); i++)
  5.     {
  6.         if (((str[i] >= -96) && (str[i] <= -81)) || ((str[i] >= -128) && (str[i] <= -97))) str[i] += 64;
  7.         else
  8.         {
  9.             if ((str[i] >= -32) && (str[i] <= -17)) str[i] += 16;
  10.             else
  11.             {
  12.                 if (str[i] == -15) str[i] = -72;
  13.                 if (str[i] == -16) str[i] = -88;
  14.             }
  15.         }
  16.     }
  17. }
  18. bool checkInputedString(char* str)
  19. {
  20.     int a = strlen(str);
  21.     if (a > 300) return false;
  22.     for (int i = 0; i < a; i++)
  23.     {
  24.         if ((str[i] < 32) && (str[i] >= 0)) return false;
  25.     }
  26.     return true;
  27. }
  28. void inputStringAsciiCorrect(char* *pSource)
  29. {
  30.     char * temp = (char*)malloc(301*sizeof(char));
  31.     temp = (char*) memset(temp, NULL, 1);
  32.     for (size_t i = 0; i < strlen(*pSource); i++)
  33.     {
  34.         if (((*pSource[i])>31) || ((*pSource[i])<0))
  35.         {
  36.             strncat(temp, &(*pSource)[i], 1);
  37.         }
  38.     }
  39.     free(*pSource);
  40.     *pSource = temp;
  41.  
  42. }
  43. void cesarCorrect(char* str)
  44. {
  45.     for (size_t i = 0; i < strlen(str); i++)
  46.     {
  47.         if (str[i]>-96)
  48.         {
  49.             if (str[i]<125)
  50.                 str[i] += 3;
  51.             else str[i] = str[i] - 223;
  52.         }
  53.  
  54.     }
  55. }
  56.  
  57. int main(int argc, char* argv[])
  58. {
  59.     setlocale(0, "ru");
  60.  
  61.     char* *str;
  62.     char* source = (char*)malloc(sizeof(char)* 301);
  63.     str = &source;
  64.     if (argc == 1)
  65.     {
  66.         int i = 0;
  67.         printf("input string: \n");
  68.         gets(*str);
  69.         int t = *str[i] - 0;
  70.         std::cout << *str << std::endl;
  71.         std::cout << t << std::endl;
  72.         russianCorrection(*str);
  73.         t = *str[i] + 0;
  74.         std::cout << t << std::endl;
  75.         if (!checkInputedString(*str))
  76.         {
  77.             inputStringAsciiCorrect(str);
  78.             //i++;
  79.         }
  80.         cesarCorrect(*str);
  81.        
  82.        
  83.         printf(*str, "/n\n");
  84.     }
  85.     system("pause");
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement