#pragma once
#define MAX 1024
using namespace std;
class str
{
public:
str()
{
this->arr = new char[MAX];
for (int i = 0; i < MAX; i++)
{
arr[i] = '\0';
}
this->cursize = 0;
}
void insert(int pos,const char c[])
{
int n = strlen(c);
if (pos == cursize)
{
for (int i = pos; i < pos + n; i++)
{
arr[i] = c[i - pos];
}
}
else
{
for (int i = cursize - 1; i >= pos; i--)
{
arr[i + n] = arr[i];
}
for (int i = pos; i < pos + n; i++)
{
arr[i] = c[i - pos];
}
}
cursize += n;
}
void delestr(int begin,int end)
{
if (begin > end)return;
int n = end - begin + 1;
if (end == cursize - 1)
{
for (int i = begin; i <= end; i++)
{
arr[i] = '\n';
}
cursize -= n;
}
else
{
for (int i = begin, j = begin + n; j < cursize; i++, j++)
{
arr[i] = arr[j];
}
for (int i = cursize; i < cursize + n; i++)
{
arr[i] = '\n';
}
cursize -= n;
}
}
void ptstr()
{
if (cursize == 0)return;
for (int i = 0; i < cursize; i++)
{
cout << arr[i];
}
cout << endl;
}
~str()
{
if (this->arr != nullptr)
{
this->arr = nullptr;
delete[] this->arr;
}
}
int cursize;
char* arr;
};