class Pepega:
def __init__(self) -> None:
print("this pepega()")
class Smart(Pepega):
def __init__(self):
print("__init__Smart")
super().__init__()
class Monkey(Pepega):
def __init__(self):
print("Monkey()")
super().__init__()
class SmartMonk(Monkey, Smart):
def __init__(self):
print("__init__SmartMonk")
super().__init__()
smrtM = SmartMonk()
主页
/
user-513958
podpivas's questions
std::vector create() {
std::vector<HeavyType> temp = {... 10 objects }; // супер тяжелые объекты
return temp;
}
在实践中,我从来没有遇到过这个问题,问题是在面试时,我不能
为了理解 rofl 是什么,我要补充一点,假设 HeavyType 是一个非常重的数据类型
class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {}
class Solution {
func mostWordsFound(_ sentences: [String]) -> Int {
sentences.reduce(0) { max($0, numWords($1)) }
}
func numWords(_ string: String) -> Int {
string.reduce(1) { $0 + ($1 == " " ? 1 : 0) }
}
}
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <Windows.h>
#include <map>
using namespace std;
class String {
private:
unsigned int length;
char* cstring;
void clean() {
if (cstring) {
delete[] cstring;
}
length = 0;
}
public:
String(const char* str) : length(strlen(str)), cstring(new char[length + 1]) {
strcpy(cstring, str);
cout << "ctor" << endl;
}
String() : String("") {
}
String(int size, char symbol) : cstring(new char[size + 1]), length(size) {
if (size) {
memset(cstring, symbol, size);
cstring[size] = '\0';
}
}
String(const String& other) {
length = other.length;
cstring = new char[length + 1];
strcpy(cstring, other.cstring);
}
String& operator=(const String& other) {
cout << "String& operator=(const String& other)" << endl;
if (this == &other)
return *this;
clean();
length = other.length;
cstring = new char[length + 1];
strcpy(cstring, other.cstring);
return *this;
}
String(String&& other) noexcept {
length = other.length;
cstring = other.cstring;
other.cstring = nullptr;
}
String& operator=(String&& other) noexcept {
cout << "=&&" << endl;
if (this == &other)
return *this;
clean();
length = other.length;
cstring = other.cstring;
other.cstring = nullptr;
return *this;
}
String& operator +=(String const& other) {
cout << "=+" << endl;
if (other.length) {
unsigned int size = length + other.length;
char* buff = new char[size + 1];
strcpy(buff, cstring);
strcat(buff, other.cstring);
clean();
cstring = buff;
length = size;
buff = nullptr;
return *this;
}
}
~String() {
clean();
cout << "dtor" << endl;
}
inline bool isEmpty() { return length == 0; }
inline unsigned int getLength() { return length; }
inline const char* c_str() const { return cstring; }
bool operator==(const String& t) const {
return length == t.length && strcmp(cstring, t.cstring) == 0;
}
bool operator !=(const String& t) const {
return !(operator==(t));
}
char& operator[](const int i) {
return cstring[i];
}
void stringLow() {
for (int j = 0; j < length; ++j)
cstring[j] = (char)(tolower(cstring[j]));
}
void stringUp() {
for (int j = 0; j < length; ++j)
cstring[j] = (char)(toupper(cstring[j]));
}
void reverse() {
for (int i = 0; i < length / 2; i++) {
swap(cstring[i], cstring[length - i - 1]);
}
}
friend String operator+(String l, const String& r) {
return l += r;
}
friend istream& operator >>(istream& is, String& obj) {
char* buff = new char[99];
memset(&buff[0], 0, sizeof(buff));
is >> buff;
obj = String(buff);
delete[] buff;
return is;
}
friend ostream& operator <<(ostream& os, const String& obj) {
os << obj.cstring;
return os;
}
};
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
String var("Люблю ");
String var2("много пива");
String var3 = var + var2;
}