Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include "string.h"
- #include "windows.h"
- //??? - ????, LIFO
- typedef struct snd
- {
- snd *n;
- char str[10];
- } ListString;
- using namespace std;
- class List //????? ??????
- {
- private:
- snd *Head; //????????? ?? ????????? ???????? ??????? ??? ?????? ?????? ??????
- int last_length; //????????????? ?????????? ???????? ?????
- int length; //????? ???? ??????
- public:
- List()
- {
- Head = NULL; //??????????? ? ????????????? ????????? ?????? ?????????
- length = 0;
- last_length = 0;
- }
- List(char * text);
- ~List(); //???????? ???????????. ??? ?????????? ??????? ?? ?????
- void Fill(char* x); //???????? ???????, ??????????? ??????
- void Add(char* x); //???????? ???????, ??????????? ? ????? ??????
- void Show(); //???????? ?????????????????? ?????? ?? ??????
- void Reverse(); //?????? ???????? ???? ?? ???????????????
- int getLength(); //?????? ? ???????? length
- char * getString(); //?????????? ????????? ?? ??????
- };
- List::getLength()
- {
- return length;
- }
- void List::Reverse()
- {
- snd *temp=Head; //?????????? ?????????, ??????? ?????????? ?? ????? ?????? ?????? ??????
- string out = "";
- while (temp != NULL) //?? ??? ??? ???? ?? ???????? ?????? ????????
- {
- for(int i = 0; i < 10; i++)
- {
- if(temp->str[i] == 0)
- break;
- if(isalpha(temp->str[i]))
- {
- if(isupper(temp->str[i]))
- {
- temp->str[i] = tolower(temp->str[i]);
- }
- else
- {
- temp->str[i] = toupper(temp->str[i]);
- }
- }
- }
- out = string(temp->str).substr(0,10) + "" + out ;
- temp = temp->n;
- }
- }
- List::~List() //?????????? ??????? ?? ?????
- {
- while (Head != NULL) //???? ?? ?????? ?? ?????
- {
- snd *temp = Head->n; //????????? ?????????? ??? ???????? ?????? ?????????? ????????
- delete Head; //??????????? ????? ???????????? ??????
- Head = temp; //?????? ????? ?? ?????????
- }
- }
- List::List(char * text) //???????? ??????, ????????? ??? ????? ???????
- {
- Head = NULL;
- Fill(text);
- }
- void List::Fill(char* text) //??????? ?????????? ????????? ? ??????
- {
- while (Head != NULL) //???? ?? ?????? ?? ?????
- {
- snd *temp = Head->n; //????????? ?????????? ??? ???????? ?????? ?????????? ????????
- delete Head; //??????????? ????? ???????????? ??????
- Head = temp; //?????? ????? ?? ?????????
- }
- length = 0;
- last_length = 0;
- Add(text); //??????? ?????????? ??????
- }
- void List::Add(char* text) //??????? ?????????? ????????? ? ??????
- {
- //????? ? ???, ??? ????? ? ??? ????????? ??????? ??????? ?? ???????? ?????????, ?? ????????? ??? ?? ????? ? ?????? ?????
- //???????? ????????? ????????
- int i, text_length = strlen(text);
- snd *temp;
- string temp_text = text;
- if(last_length != 0)
- {
- if(text_length + last_length < 10) //???? ???? ? ??????????? ????? ?????? ?? ?? ???????? ??????? ??????? (? ????????? ????? "?", ????????? "?")
- {
- memccpy(Head->str + last_length, &temp_text[0], 0, text_length); //???????? ???????? ?? ???????? ?????? ? ????? ???????? ???????? (????? ??????????)
- Head->str[text_length + last_length] = 0;
- last_length += text_length;
- length += text_length;
- return;
- }
- else
- {
- memccpy(Head->str + last_length, &temp_text[0], 0, 10 - last_length); //????? ?????????? - ?? ?????? ????????? ????????? ??????? ?? 10 - last_length
- temp_text = temp_text.substr(10-last_length); //??????? ???? ?????? ???, ????? ?? ?? ???????? ? ??? ????????, ??????? ????????? ???????? ??????? ?????
- text_length = temp_text.length(); //????????? ????????? ??????????
- }
- }
- length += text_length; //????????? ??????? ????? ??????
- for(i = 0; i < text_length / 10; i++) //????? ?? ?????? ? ?????????? ? 10 ???????? ? ?????????? ? ????
- {
- temp = new snd;
- memccpy(temp->str, &temp_text[i*10], 0, 10); //??????? ?? 10 ???????? ? ?????????? ???????? ? ????
- temp->n = Head; //?????????, ??? ????. ??????? ??? ?????? ?? ?????? Head
- Head = temp; //?????????, ??? ????????? ???????? ??????? ??? ?????? ??? ?????????
- }
- if(text_length % 10 != 0) //???? ??????? ????? ??????, ??????? ?? ????????? ???????? ??????? ??????, ??
- {
- last_length = text_length - i*10; //??????? ??????? ???????? ?????? ? ???????? ?
- temp = new snd;
- memccpy(temp->str, &temp_text[i*10], 0, text_length - i*10);
- temp->str[text_length % 10] = 0; //???? ? ????? ??????
- temp->n = Head; //?????????, ??? ????. ??????? ??? ?????? ?? ?????? Head
- Head = temp; //?????????, ??? ????????? ???????? ??????? ??? ?????? ??? ?????????
- }
- }
- void List::Show() //??????? ??????????? ?????? ?? ??????
- {
- snd *temp=Head; //?????????? ?????????, ??????? ?????????? ?? ????? ?????? ?????? ??????
- string out = "";
- while (temp != NULL) //?? ??? ??? ???? ?? ???????? ?????? ????????
- {
- out = string(temp->str).substr(0,10) + "" + out ;
- temp = temp->n;
- }
- cout << out << endl;
- }
- char* List::getString()
- {
- snd *temp=Head; //?????????? ?????????, ??????? ?????????? ?? ????? ?????? ?????? ??????
- char * result = new char[length ];
- string out = "";
- while (temp != NULL) //?? ??? ??? ???? ?? ???????? ?????? ????????
- {
- out = string(temp->str).substr(0,10) + "" + out ;
- temp = temp->n;
- }
- strcpy(result, out.c_str());
- return result;
- }
- int main()
- {
- //system ("chcp 1251");
- //char *str = "??????? ?????????? ????????? ??????????????!";
- char *str = "Tasks";
- List *a = new List(str);
- a->Show();
- a->Add("MUST");
- a->Show();
- a->Add("Be");
- a->Show();
- a->Add("Done");
- a->Show();
- a->Add("By");
- a->Show();
- a->Add("Yourself");
- a->Show();
- a->Add("And only by yourself");
- a->Show();
- cout << "Length - " << a->getLength()<<endl;
- a->Reverse();
- cout << "Reverse - ";
- a->Show();
- char * arr = new char [a->getLength() + 1]; //???????? ?????? ??? ?????? + '0'
- strcpy(arr, a->getString());
- cout << "Get string - " <<arr << endl;
- a->Fill("Overrided text");
- a->Show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement