#include <iostream>
#include <cstring>
#include <cassert>
using namespace std;
class MyString
{
private:
char *m_data;
int m_length;
public:
MyString(const char *source="")
{
assert(source); // make sure source isn't a null string
// Find the length of the string
// Plus one character for a terminator
m_length = std::strlen(source) + 1;
// Allocate a buffer equal to this length
m_data = new char[m_length];
// Copy the parameter string into our internal buffer
for (int i{ 0 }; i < m_length; ++i)
m_data[i] = source[i];
// Make sure the string is terminated
m_data[m_length-1] = '\0';
}
~MyString() // destructor
{
// We need to deallocate our string
delete[] m_data;
}
char* getString() { return m_data; }
int getLength() { return m_length; }
};
int main() {
// your code goes here
MyString hello("Hello, world!");
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNhc3NlcnQ+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBNeVN0cmluZwp7CnByaXZhdGU6CiAgICBjaGFyICptX2RhdGE7CiAgICBpbnQgbV9sZW5ndGg7CiAKcHVibGljOgogICAgTXlTdHJpbmcoY29uc3QgY2hhciAqc291cmNlPSIiKQogICAgewogICAgICAgIGFzc2VydChzb3VyY2UpOyAvLyBtYWtlIHN1cmUgc291cmNlIGlzbid0IGEgbnVsbCBzdHJpbmcKIAogICAgICAgIC8vIEZpbmQgdGhlIGxlbmd0aCBvZiB0aGUgc3RyaW5nCiAgICAgICAgLy8gUGx1cyBvbmUgY2hhcmFjdGVyIGZvciBhIHRlcm1pbmF0b3IKICAgICAgICBtX2xlbmd0aCA9IHN0ZDo6c3RybGVuKHNvdXJjZSkgKyAxOwogICAgICAgIAogICAgICAgIC8vIEFsbG9jYXRlIGEgYnVmZmVyIGVxdWFsIHRvIHRoaXMgbGVuZ3RoCiAgICAgICAgbV9kYXRhID0gbmV3IGNoYXJbbV9sZW5ndGhdOwogICAgICAgIAogICAgICAgIC8vIENvcHkgdGhlIHBhcmFtZXRlciBzdHJpbmcgaW50byBvdXIgaW50ZXJuYWwgYnVmZmVyCiA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