-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.hpp
More file actions
57 lines (45 loc) · 1.2 KB
/
Copy pathstring.hpp
File metadata and controls
57 lines (45 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef SJTU_STRING_HPP
#define SJTU_STRING_HPP
#include <utility>
namespace sjtu {
class string {
private:
char alpha[65];
int len = 0;
public:
string() {
alpha[0] = '\0';
}
int length() const {
return len;
}
string(const string &other) {
for (int i = 0; i < other.length(); i++)
alpha[i] = other.alpha[i];
alpha[other.length()] = '\0';
len = other.length();
}
friend std::istream &operator>>(std::istream &is, string &s) {
std::string s_;
is >> s_;
strcpy(s.alpha, s_.c_str());
s.len = s_.length();
return is;
}
bool operator==(const std::string &s_) {
if (len != s_.length()) return 0;
for (int i = 0; i < len; i++) {
if (alpha[i] != s_[i]) return 0;
}
return 1;
}
bool operator<(const string &s_) const {
if (strcmp(alpha, s_.alpha) < 0) return 1;
else return 0;
}
char &operator[](const int &i) {
return alpha[i];
}
};
}
#endif