Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <cstring>
- #include <vector>
- #include <cstdio>
- #include <string>
- #include <cmath>
- #include <queue>
- #include <set>
- #include <map>
- #include <complex>
- using namespace std;
- typedef long long ll;
- typedef double db;
- typedef pair<int,int> pii;
- typedef vector<int> vi;
- #define de(x) cout << #x << "=" << x << endl
- #define rep(i,a,b) for(int i=a;i<(b);++i)
- #define all(x) (x).begin(),(x).end()
- #define sz(x) (int)(x).size()
- #define mp make_pair
- #define pb push_back
- #define fi first
- #define se second
- #define setIO(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout)
- int toint(string s){int r=0;rep(i,0,sz(s))r=r*10+s[i]-'0';return r;}
- struct Widget{
- ll t,x,y,border,space;
- vector<string> V;
- Widget(int t=0,int x=0,int y=0):t(t),x(x),y(y),border(0),space(0){}
- };
- map<string,Widget> Mp;
- char s[1000];
- void go(Widget&c){
- if(c.t == 0) return;
- for(auto e : c.V){
- Widget& to = Mp[e];
- go(to);
- if(c.t == 1){
- c.x = max(c.x,to.x+c.border*2);
- c.y += to.y;
- }
- if(c.t == 2){
- c.y = max(c.y,to.y+c.border*2);
- c.x += to.x;
- }
- }
- if(sz(c.V)){
- if(c.t == 1) c.y += c.border*2+(sz(c.V)-1)*c.space;
- if(c.t == 2) c.x += c.border*2+(sz(c.V)-1)*c.space;
- }
- c.t = 0;
- }
- int main(){
- int n;scanf("%d",&n);
- gets(s);
- rep(i,0,n){
- gets(s);
- vector<string> a;
- for(char* p=strtok(s," .,()");p;p=strtok(NULL," .,()")) a.pb(p);
- if(a[0] == "Widget") Mp[a[1]] = Widget(0,toint(a[2]),toint(a[3]));
- else if(a[0] == "VBox") Mp[a[1]] = Widget(1);
- else if(a[0] == "HBox") Mp[a[1]] = Widget(2);
- else if(a[1] == "pack") Mp[a[0]].V.pb(a[2]);
- else if(a[1] == "set_border") Mp[a[0]].border = toint(a[2]);
- else if(a[1] == "set_spacing") Mp[a[0]].space = toint(a[2]);
- }
- for(auto e:Mp){
- go(e.se);
- cout << e.fi << " " << e.se.x << " " << e.se.y << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement