救救 /kel/kel/kel/kel/kel/kel
  • 板块学术版
  • 楼主Lovely_Elaina
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/8/26 19:34
  • 上次更新2024/8/26 21:26:27
查看原帖
救救 /kel/kel/kel/kel/kel/kel
781159
Lovely_Elaina楼主2024/8/26 19:34
/*
我们定义 byte short int long 为基础变量,结构体为结构体变量
定义 tableType 为变量类型对应的属性
定义 tableVar 为变量名对应的变量类型
*/
#include <bits/stdc++.h>
// #define int long long
// #define double long double
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define endl '\n' 
using namespace std;
typedef long long ll;
// const int eps = 1e-9;
const int N = 8*1e2+5;

struct type{
    string s;
    ll align; // 对齐
    int k; // 子变量个数(基础变量为 0)
    // 变量类型 变量名
    vector<pair<string,string> > v;
}table[N];
int cntType;

struct variable{
    string name;
    string node;
    int l,r;
}var[N];
int cntVar;

map<string,int > tableType;
map<string,int > tableVar;

int add; // 已用地址右边界

inline void init(){
    table[++cntType].s = "byte";
    table[cntType].align = 1;
    table[cntType].k = 0;
    tableType["byte"] = cntType;

    table[++cntType].s = "short";
    table[cntType].align = 2;
    table[cntType].k = 0;
    tableType["short"] = cntType;

    table[++cntType].s = "int";
    table[cntType].align = 4;
    table[cntType].k = 0;
    tableType["int"] = cntType;

    table[++cntType].s = "long";
    table[cntType].align = 8;
    table[cntType].k = 0;
    tableType["long"] = cntType;
}

inline int find(int addr){
    return 1;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
    
    // freopen("app.in","r",stdin);
    // freopen("app.out","w",stdout);

    init();

    int T,k,op;
    ll addr;
    string s,t,n;

    cin >> T; 
    while(T--){
        cin >> op;
        if(op == 1){
            cin >> s >> k;
            table[++cntType].s = s;
            table[cntType].k = k;
            table[cntType].align = 0;
            for(int i = 1; i <= k; i++){
                cin >> t >> n;
                table[cntType].v.push_back(make_pair(t,n));
                table[cntType].align = max(table[cntType].align,table[tableType[t]].align);
            }
            tableType[s] = cntType;
        }else if(op == 2){
            cin >> t >> n;
            var[++cntVar].name = n;
            var[cntVar].node = t;
            tableVar[n] = cntVar;
        }else if(op == 3){
            cin >> s;

        }else if(op == 4){
            cin >> addr;
            find(addr);
        }
    }

    for(int i = 1; i <= cntType; i++){
        cout << table[i].s << " ";
        cout << table[i].align << " ";
        for(int j = 0; j < k; j++)
            cout << "(" << table[i].v[j].first << ")" << table[i].v[j].second << " ";
        cout << endl;
    }
	return 0; 
} 
5
1 a 2
short aa
int ab
1 b 2
a ba
long bb
2 b x
3 x.ba.ab
4 10

把 init 函数里的注释取消就会报错分段错误(?)

2024/8/26 19:34
加载中...