Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "string.h"
  4. #include "windows.h"
  5.  
  6. //??? - ????, LIFO
  7.  
  8. typedef struct snd
  9. {
  10. snd *n;
  11. char str[10];
  12. } ListString;
  13.  
  14. using namespace std;
  15.  
  16. class List //????? ??????
  17. {
  18. private:
  19. snd *Head; //????????? ?? ????????? ???????? ??????? ??? ?????? ?????? ??????
  20. int last_length; //????????????? ?????????? ???????? ?????
  21. int length; //????? ???? ??????
  22. public:
  23. List()
  24. {
  25. Head = NULL; //??????????? ? ????????????? ????????? ?????? ?????????
  26. length = 0;
  27. last_length = 0;
  28. }
  29. List(char * text);
  30. ~List(); //???????? ???????????. ??? ?????????? ??????? ?? ?????
  31. void Fill(char* x); //???????? ???????, ??????????? ??????
  32. void Add(char* x); //???????? ???????, ??????????? ? ????? ??????
  33. void Show(); //???????? ?????????????????? ?????? ?? ??????
  34. void Reverse(); //?????? ???????? ???? ?? ???????????????
  35. int getLength(); //?????? ? ???????? length
  36. char * getString(); //?????????? ????????? ?? ??????
  37.  
  38. };
  39.  
  40. List::getLength()
  41. {
  42. return length;
  43. }
  44.  
  45. void List::Reverse()
  46. {
  47.  
  48. snd *temp=Head; //?????????? ?????????, ??????? ?????????? ?? ????? ?????? ?????? ??????
  49.  
  50. string out = "";
  51.  
  52. while (temp != NULL) //?? ??? ??? ???? ?? ???????? ?????? ????????
  53. {
  54. for(int i = 0; i < 10; i++)
  55. {
  56. if(temp->str[i] == 0)
  57. break;
  58. if(isalpha(temp->str[i]))
  59. {
  60. if(isupper(temp->str[i]))
  61. {
  62. temp->str[i] = tolower(temp->str[i]);
  63. }
  64. else
  65. {
  66. temp->str[i] = toupper(temp->str[i]);
  67. }
  68. }
  69. }
  70. out = string(temp->str).substr(0,10) + "" + out ;
  71. temp = temp->n;
  72. }
  73. }
  74.  
  75. List::~List() //?????????? ??????? ?? ?????
  76. {
  77. while (Head != NULL) //???? ?? ?????? ?? ?????
  78. {
  79. snd *temp = Head->n; //????????? ?????????? ??? ???????? ?????? ?????????? ????????
  80. delete Head; //??????????? ????? ???????????? ??????
  81. Head = temp; //?????? ????? ?? ?????????
  82. }
  83. }
  84.  
  85. List::List(char * text) //???????? ??????, ????????? ??? ????? ???????
  86. {
  87. Head = NULL;
  88.  
  89. Fill(text);
  90. }
  91.  
  92. void List::Fill(char* text) //??????? ?????????? ????????? ? ??????
  93. {
  94. while (Head != NULL) //???? ?? ?????? ?? ?????
  95. {
  96. snd *temp = Head->n; //????????? ?????????? ??? ???????? ?????? ?????????? ????????
  97. delete Head; //??????????? ????? ???????????? ??????
  98. Head = temp; //?????? ????? ?? ?????????
  99. }
  100. length = 0;
  101. last_length = 0;
  102.  
  103. Add(text); //??????? ?????????? ??????
  104. }
  105.  
  106. void List::Add(char* text) //??????? ?????????? ????????? ? ??????
  107. {
  108. //????? ? ???, ??? ????? ? ??? ????????? ??????? ??????? ?? ???????? ?????????, ?? ????????? ??? ?? ????? ? ?????? ?????
  109. //???????? ????????? ????????
  110. int i, text_length = strlen(text);
  111. snd *temp;
  112. string temp_text = text;
  113.  
  114. if(last_length != 0)
  115. {
  116. if(text_length + last_length < 10) //???? ???? ? ??????????? ????? ?????? ?? ?? ???????? ??????? ??????? (? ????????? ????? "?", ????????? "?")
  117. {
  118. memccpy(Head->str + last_length, &temp_text[0], 0, text_length); //???????? ???????? ?? ???????? ?????? ? ????? ???????? ???????? (????? ??????????)
  119. Head->str[text_length + last_length] = 0;
  120.  
  121. last_length += text_length;
  122.  
  123. length += text_length;
  124. return;
  125. }
  126. else
  127. {
  128. memccpy(Head->str + last_length, &temp_text[0], 0, 10 - last_length); //????? ?????????? - ?? ?????? ????????? ????????? ??????? ?? 10 - last_length
  129.  
  130. temp_text = temp_text.substr(10-last_length); //??????? ???? ?????? ???, ????? ?? ?? ???????? ? ??? ????????, ??????? ????????? ???????? ??????? ?????
  131. text_length = temp_text.length(); //????????? ????????? ??????????
  132. }
  133. }
  134. length += text_length; //????????? ??????? ????? ??????
  135.  
  136. for(i = 0; i < text_length / 10; i++) //????? ?? ?????? ? ?????????? ? 10 ???????? ? ?????????? ? ????
  137. {
  138. temp = new snd;
  139. memccpy(temp->str, &temp_text[i*10], 0, 10); //??????? ?? 10 ???????? ? ?????????? ???????? ? ????
  140. temp->n = Head; //?????????, ??? ????. ??????? ??? ?????? ?? ?????? Head
  141. Head = temp; //?????????, ??? ????????? ???????? ??????? ??? ?????? ??? ?????????
  142. }
  143.  
  144. if(text_length % 10 != 0) //???? ??????? ????? ??????, ??????? ?? ????????? ???????? ??????? ??????, ??
  145. {
  146. last_length = text_length - i*10; //??????? ??????? ???????? ?????? ? ???????? ?
  147.  
  148. temp = new snd;
  149. memccpy(temp->str, &temp_text[i*10], 0, text_length - i*10);
  150. temp->str[text_length % 10] = 0; //???? ? ????? ??????
  151. temp->n = Head; //?????????, ??? ????. ??????? ??? ?????? ?? ?????? Head
  152. Head = temp; //?????????, ??? ????????? ???????? ??????? ??? ?????? ??? ?????????
  153. }
  154.  
  155. }
  156.  
  157. void List::Show() //??????? ??????????? ?????? ?? ??????
  158. {
  159. snd *temp=Head; //?????????? ?????????, ??????? ?????????? ?? ????? ?????? ?????? ??????
  160.  
  161. string out = "";
  162.  
  163. while (temp != NULL) //?? ??? ??? ???? ?? ???????? ?????? ????????
  164. {
  165. out = string(temp->str).substr(0,10) + "" + out ;
  166. temp = temp->n;
  167. }
  168. cout << out << endl;
  169. }
  170.  
  171. char* List::getString()
  172. {
  173.  
  174.  
  175. snd *temp=Head; //?????????? ?????????, ??????? ?????????? ?? ????? ?????? ?????? ??????
  176. char * result = new char[length ];
  177.  
  178. string out = "";
  179.  
  180. while (temp != NULL) //?? ??? ??? ???? ?? ???????? ?????? ????????
  181. {
  182. out = string(temp->str).substr(0,10) + "" + out ;
  183. temp = temp->n;
  184. }
  185.  
  186. strcpy(result, out.c_str());
  187.  
  188. return result;
  189. }
  190.  
  191. int main()
  192. {
  193. //system ("chcp 1251");
  194.  
  195. //char *str = "??????? ?????????? ????????? ??????????????!";
  196. char *str = "Tasks";
  197. List *a = new List(str);
  198.  
  199. a->Show();
  200. a->Add("MUST");
  201. a->Show();
  202. a->Add("Be");
  203. a->Show();
  204. a->Add("Done");
  205. a->Show();
  206. a->Add("By");
  207. a->Show();
  208. a->Add("Yourself");
  209. a->Show();
  210. a->Add("And only by yourself");
  211. a->Show();
  212.  
  213. cout << "Length - " << a->getLength()<<endl;
  214.  
  215. a->Reverse();
  216. cout << "Reverse - ";
  217. a->Show();
  218.  
  219. char * arr = new char [a->getLength() + 1]; //???????? ?????? ??? ?????? + '0'
  220. strcpy(arr, a->getString());
  221.  
  222. cout << "Get string - " <<arr << endl;
  223.  
  224. a->Fill("Overrided text");
  225. a->Show();
  226.  
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement