一系列小的题目

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class A
{
public:
A() :c(3), b©, a(b) {}
public:
int a;
int b;
int c;
};
class MyString
{
public:
explicit MyString(char *ch, size_t length);
MyString(const MyString &other);
MyString & operator=(const MyString &other);
void printch()
{
cout << this->str_ << endl;
}
private:
size_t length_;
char *str_;
};
MyString::MyString(char *ch, size_t length)
{
this->length_ = length;
this->str_ = new char[this->length_];
strcpy(this->str_, ch);
}
MyString::MyString(const MyString &other)
{
this->length_ = other.length_;
this->str_ = new char[this->length_];
strcpy(this->str_, other.str_);
}
MyString& MyString::operator=(const MyString &other)
{
if (this == &other)
{
return *this;
}
delete[] this->str_;
this->length_ = other.length_;
this->str_ = new char[this->length_];
strcpy(this->str_, other.str_);
return *this;
}
void fun(char *&a)//1 metherd
{
a = (char *)malloc(128 * sizeof(char));
memset(a, ‘E’, 128 * sizeof(char));
}
void fun1(char **a)//2 metherd
{
*a = (char *)malloc(128 * sizeof(char));
memset(*a, ‘E’, 128 * sizeof(char));
}
pair<int, int> get_target_up(vector vec, int target)
{
map<int, int> mapint;
pair<int, int> res;
for (int i = 0; i < vec.size(); i++)
{
auto iter = mapint.find(vec[i]);
if (iter != mapint.end())
{
res.first = iter->second;
res.second = i;
return res;
}
mapint[target - vec[i]] = i;
}
}
int main()
{
/test 1/
A a;
cout << a.a<<" “<< a.b<<” "<< a.c << endl;
/test 2/
MyString mys(“abcdf”, 12);
mys.printch();
MyString mys1 = mys;
mys1.printch();
char ch[4] = “123”;
cout << sizeof(ch) << " " << strlen(ch) << endl;
/test 3/
char *astr = NULL;
fun1(&astr);
cout << astr[50] << endl;
/test 4/
pair<int, int> res = get_target_up(vector{3,3}, 6);
cout << res.first << " " << res.second << endl;
system(“pause”);
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值