Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. //#include "riesenie4.h"
  7.  
  8. #ifndef _RIESENIE_H_
  9. #define _RIESENIE_H_
  10.  
  11. #endif
  12.  
  13. const int DUMMY_INT = -999;
  14. const bool DUMMY_BOOL = false;
  15. char DUMMY_CHARS[] = "";
  16. const unsigned int MAX = 256;
  17.  
  18. //pomocne funkcie
  19. bool isDelimiter(const char *c) {
  20. return (*c == ' ' || *c == '.' || *c == ',' || *c == ';'
  21. || *c == '?' || *c == '!' || *c == ':' || *c == '-');
  22. }
  23.  
  24. //1. uloha
  25. int numberOfWords(const char *text) {
  26. if (text == nullptr) {
  27. return 0;
  28. }
  29.  
  30. int num = 0;
  31. bool word = false;
  32.  
  33. for (const char *i = text; *i != '\0';++i) {
  34. if (isDelimiter(i)) {
  35. word = false;
  36. }
  37. else if (!word) {
  38. word = true;
  39. ++num;
  40. }
  41. }
  42. return num;
  43. }
  44.  
  45. const char *pointerToNthWord(const char *text, int order) {
  46. if (text == nullptr) {
  47. return "";
  48. }
  49.  
  50. int num = 0;
  51. bool word = false;
  52.  
  53. for (const char *i = text; *i != '\0'; ++i) {
  54. if (isDelimiter(i)) {
  55. word = false;
  56. }
  57. else if (!word) {
  58. word = true;
  59. if (order == num) {
  60. return i;
  61. }
  62. ++num;
  63. }
  64. }
  65. return "";
  66. }
  67.  
  68. //2. uloha
  69. char *getNthWord(const char *text, char *word, int order) { //TODO pozri funkcie strcpy a strcat
  70. if (word == nullptr) {
  71. static char empty[1] = { '\0' };
  72. return empty;
  73. }
  74.  
  75. if ((text == nullptr) || (order > numberOfWords(text))) {
  76. *word = '\0';
  77. return word;
  78. }
  79.  
  80. char *begin = word;
  81.  
  82. for (const char *i = pointerToNthWord(text, order); *i != '\0'; ++i) {
  83. if (isDelimiter(i)) {
  84. break;
  85. }
  86. else {
  87. *begin = *i;
  88. begin++;
  89. }
  90. }
  91.  
  92. *begin = '\0';
  93. return word;
  94. }
  95.  
  96. //3. uloha
  97. char *listOfSelectedWords(const char *text, char *output, const int *listOfOrders, int numberOfOrders) {
  98. return DUMMY_CHARS;
  99. }
  100. //4.uloha
  101. void sortAccordingToAsciiValues(char **listOfWords, int count) {
  102. }
  103.  
  104. void sortWithSmallLetters(char **listOfWords, int count) {
  105. }
  106.  
  107. //5.uloha
  108. void sortWithSmallAndCh(char **listOfWords, int count) {
  109. }
  110.  
  111. char *sortAccordingToFuncion(const char *text, char *output, void sortingFunction(char **arrayOfText, int count)) {
  112. return DUMMY_CHARS;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement