Guest User

Untitled

a guest
Dec 3rd, 2019
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using namespace std;
  2.  
  3. int encode(char*, char*);
  4.  
  5. int main()
  6. {
  7. char str[1000];
  8. cin.getline(str, 999);
  9. char* res = new char[strlen(str)+1];
  10. encode(str, res);
  11.  
  12. cout << res << endl;
  13.  
  14.  
  15. if (res != nullptr)
  16. {
  17. delete[] res;
  18. res = nullptr;
  19. }
  20. }
  21.  
  22. int encode(char * src, char * res)
  23. {
  24. char * ptr = src;
  25. unsigned i = 0;
  26. while (*ptr != '\0') {
  27. if ((*ptr >= 'A' && *ptr <= 'Z') || (*ptr >= 'a' && *ptr <= 'z'))
  28. {
  29. if ((*ptr >= 'A' && *ptr < 'X') || (*ptr >= 'a' && *ptr < 'x'))
  30. {
  31. res[i++] = *ptr + 3;
  32. }
  33. else {
  34. res[i++] = *ptr - 23;
  35. }
  36. }
  37. else {
  38. res[i++] = *ptr;
  39. }
  40. ptr++;
  41. }
  42. res[i] = '\0';
  43. return 0;
  44. }
RAW Paste Data