#include "pt4.h"
using namespace std;
class TextView
{
int x = 0, y = 0;
int width = 1, height = 1;
public:
void GetOrigin(int& x, int& y);
void SetOrigin(int x, int y);
void GetSize(int& width, int& height);
void SetSize(int width, int height);
};
void TextView::GetOrigin(int& x, int& y)
{
x = this->x;
y = this->y;
}
void TextView::SetOrigin(int x, int y)
{
this->x = x;
this->y = y;
}
void TextView::GetSize(int& width, int& height)
{
width = this->width;
height = this->height;
}
void TextView::SetSize(int width, int height)
{
this->width = width;
this->height = height;
}
class Shape
{
protected:
int x1; int y1; int x2; int y2;
public:
Shape(int x1, int y1, int x2, int y2):x1(x1), y1(y1), x2(x2), y2(y2){}
virtual string GetInfo() = 0;
virtual void MoveBy(int a, int b) = 0;
bool operator <(Shape &ob) const
{
if(x1 == ob.x1)
{
if(y1 == ob.y1)
{
if(x2 == ob.x2)
return y2 < ob.y2;
else return x2 < ob.x2;
}
else return y1 < ob.y1;
}
else return x1 < ob.x1;
}
};
class RectShape : public Shape
{
public:
RectShape(int x1, int y1, int x2, int y2):Shape(x1, y1, x2, y2){}
virtual string GetInfo()
{
return "R(" + to_string(x1) + "," + to_string(y1) + ")(" + to_string(x2) + "," + to_string(y2) + ")";
//"R(%d,%d)(%d,%d)".format(x1,y1,x2,y2);
}
virtual void MoveBy(int a, int b)
{
x1 += a;
x2 += a;
y1 += b;
y2 += b;
}
};
class TextShape : public Shape
{
private:
string tview;
public:
TextShape(string tview, int x1, int y1, int x2, int y2):Shape(x1, y1, x2, y2){
this->tview = tview;
}
virtual string GetInfo()
{
return "T(" + to_string(x1) + "," + to_string(y1) + ")(" + to_string(x2) + "," + to_string(y2) + ")";
}
virtual void MoveBy(int a, int b)
{
x1 += a;
x2 += a;
y1 += b;
y2 += b;
}
};
void Solve()
{
Task("OOP2Struc3");
int N, A, B;
pt >> N;
vector<vector<int>> V;
int num;
for(int i=0; i<N; i++)
{
vector<int> v;
for(int j=0; j<5; j++)
{
pt >> num;
v.push_back(num);
}
V.push_back(v);
}
pt >> A >> B;
set<Shape> s;
for(int i=0; i<N; i++)
{
if((char)V[i][0] == 'R')
s.insert(RectShape(V[i][1], V[i][2], V[i][3], V[i][4]));
else if((char)V[i][0] == 'T')
s.insert(TextShape("T", V[i][1], V[i][2], V[i][3], V[i][4]));
}
for(auto it = s.begin(); it != s.end(); it++)
{
it->MoveBy(A, B);
it->GetInfo();
}
}
这个错误是因为set的迭代器it有const修饰符,不能对其元素进行更改。