Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class String {
- public:
- String();
- String(const String&tmp);
- String(char *str);
- ~String();
- int length();
- int find(String t);
- String &operator =(const String &);
- char &operator [](int index);
- bool operator ==(const String &tmp);
- bool operator !=(const String &tmp);
- bool operator > (const String &tmp);
- bool operator >=(const String &tmp);
- bool operator < (const String &tmp);
- bool operator <=(const String &tmp);
- friend istream &operator >>(istream &in, String &tmp);
- friend ostream &operator <<(ostream &out, const String &tmp);
- private:
- int len;
- char *str;
- };
- String::String()
- {
- this->len = 0;
- }
- String::String(const String &tmp)
- {
- for (int i = 0; i < tmp.len; ++i)
- this->str[i] = tmp.str[i];
- this->len = tmp.len;
- }
- String::String(char *str)
- {
- strncpy(this->str, str, strlen(str));
- }
- String::~String()
- {
- delete [] this->str;
- }
- int String::length()
- {
- return this->len;
- }
- String &String::operator=(const String &tmp)
- {
- strncpy(this->str, tmp.str, tmp.len);
- this->len = tmp.len;
- return *(this);
- }
- char &String::operator [](int index)
- {
- return this->str[index];
- }
- bool String::operator ==(const String &tmp)
- {
- if (strcmp(this->str, tmp.str))
- return false;
- return true;
- }
- bool String::operator !=(const String &tmp)
- {
- if (strcmp(this->str, tmp.str))
- return true;
- return false;
- }
- bool String::operator >(const String &tmp)
- {
- if (strcmp(this->str, tmp.str) > 0)
- return true;
- return false;
- }
- bool String::operator >=(const String &tmp)
- {
- if ((strcmp(this->str, tmp.str) > 0) || !strcmp(this->str, tmp.str))
- return true;
- return false;
- }
- bool String::operator <(const String &tmp)
- {
- if (strcmp(this->str, tmp.str) < 0)
- return true;
- return false;
- }
- bool String::operator <=(const String &tmp)
- {
- if ((strcmp(this->str, tmp.str) < 0) || !strcmp(this->str, tmp.str))
- return true;
- return false;
- }
- ostream &operator <<(ostream &out, const String &tmp)
- {
- out << tmp.str;
- return out;
- }
- istream &operator >>(istream &in, String &tmp)
- {
- char str[1000000];
- in.getline(str, 1000000);
- size_t inputLength = strlen(str);
- if (static_cast<char>(str[inputLength - 1]) == '\r') {
- str[inputLength - 1] = '\0';
- }
- if (tmp.len != 0)
- delete [] tmp.str;
- tmp.len = int(strlen(str));
- tmp.str = new char[tmp.len + 1];
- for (int i = 0; i < tmp.len; ++i) {
- tmp.str[i] = str[i];
- }
- tmp.str[tmp.len] = '\0';
- return in;
- }
- int main()
- {
- String str1, str2;
- char sign[3] = {};
- cin >> str1 >> sign >> str2;
- if (strlen(sign) == 1) {
- if (sign[0] == '>')
- cout << (str1 > str2 ? "YES" : "NO");
- else if (sign[0] == '<')
- cout << (str1 < str2 ? "YES" : "NO");
- } else {
- if (sign[0] == '>')
- cout << (str1 >= str2 ? "YES" : "NO");
- else if (sign[0] == '<')
- cout << (str1 <= str2 ? "YES" : "NO");
- else if (sign[0] == '=')
- cout << (str1 == str2 ? "YES" : "NO");
- else if (sign[0] == '!')
- cout << (str1 != str2 ? "YES" : "NO");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement