#9 #10 RE,有注释,求调
  • 板块P10788 sql
  • 楼主FurippuWRY
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/7/20 09:57
  • 上次更新2024/7/20 10:50:48
查看原帖
#9 #10 RE,有注释,求调
993779
FurippuWRY楼主2024/7/20 09:57

#9 #10 返回了 Received signal 6: Aborted / IOT trap.,请问原因是什么?

#include <bits/stdc++.h>

using namespace std;

int n, m;
string mc;
string k[11][301][301]; //k[表名(序号)][行][列]
map<string, int> z; // 存储字符串对应的序号
int x[110], y[110]; // 存储各字符串对应的长宽

signed main() {	
	
   	cin >> n;
   	for (int i = 1; i <= n; ++i) {
   		cin >> mc;
   		z[mc] = i;
   		cin >> x[i] >> y[i];
   		for (int j = 1; j <= x[i]; ++j) {
   			for (int w = 1; w <= y[i]; ++w) {
				cin >> k[i][j][w];
   				if (j == 1) {
   					z[k[i][j][w]] = w;
   				}
   			}
   		}
   	}
   	
   	cin >> m;
   	getline(cin, mc);
	while (m--) {
		/* 
			分离查询字符串,如 select sid,name from basic_info where grade=2
			c[1] = "sid"
			c[2] = "name"
			t = "basic_info"
			h = "grade"
			u = "2"
		*/ 
   		string ct, t, h, u, p1, p2, p3, p4, c[100];
   		getline(cin, p1);
   		int x_1 = p1.find("select ") + 7;
   		int x_2 = p1.find(" from ", x_1);
   		int x_3 = p1.find(" where ", x_2 + 5);
   		ct = p1.substr(x_1, x_2 - x_1);
   		t = p1.substr(x_2 + 6, x_3 - x_2 - 6);
   		p2 = p1.substr(x_3 + 7);
   		int ot = p2.find('=');
   		h = p2.substr(0, ot);
   		u = p2.substr(ot + 1, string::npos);
   		int cnt = 0, lst = 0;
   		if (ct.find(',') == string::npos) {
   			c[++cnt] = ct;
   		}
   		
   		// 似乎出现问题的区域
   		else {
	   		while (1) {
	   			int g = ct.find(',');
	   			c[++cnt] = ct.substr(lst, g - lst);
	   			lst += g;
	   			ct = ct.substr(g + 1, string::npos);
				if (ct.find(',') == string::npos) {
					c[++cnt] = ct;
					break;
				}
	   		}
   		}
   		// 似乎出现问题的区域
   		
   		// 输出
		int t_num = z[t];
		for (int i = 2; i <= x[t_num]; ++i) {
			bool f = 0;// 用来判断
			for (int j = 1; j <= cnt; ++j) {
				if (k[t_num][i][z[h]] != u) {
					break;
				}
				cout << k[t_num][i][z[c[j]]] << ' ';
				f = 1;
			}
			if (f) cout << '\n';
		}
   	}
    
	return 0;
}
2024/7/20 09:57
加载中...