LG10788
还剩半个小时才开始打入门赛,结果最后一题就差几分钟,恼火。
这是一道模拟题,因此我们要仔细梳理题目给的大量信息。通俗地理解,给定若干个表格,每个表格包含一行表头和若干组信息,并且有若干次询问,每次询问指定一个表格的一个关键字的内容,寻找该表格中对应关键字内容相同的信息,并输出另外指定的关键字的内容。
注意到数据范围很小,因此我们无需考虑任何优化,直接暴力模拟。首先确定所在的是哪个表格,确定表格后再枚举该表格中的信息,寻找与给定关键字内容相同的信息,再输出另外指定的关键字的内容即可。
实现时有许多细节,如输入时字符串需要分割,要输出的关键字可能有多个,也需要处理。具体见代码。
#include <bits/stdc++.h>
#define int long long
#define eps 1e-9
using namespace std;
int k,x[11],y[11],m,ans,la,lc;
string s[11][101][11],t[11];
string qa,qb,qc,qd,a;
char q1[1001],q2[1001],q3[1001],q4[1001];
signed main()
{
cin >> k;
for( int i = 1 ; i <= k ; i ++ )
{
cin >> t[i];
cin >> x[i] >> y[i];
for( int xx = 1 ; xx <= x[i] ; xx ++ )
for( int yy = 1 ; yy <= y[i] ; yy ++ )
cin >> s[i][xx][yy];
}
int T;
cin >> T;
while( T -- )
{
cin >> qa;
cin >> qa;
cin >> qb;
cin >> qb;
cin >> qc;
cin >> qc;
lc = qc.size();
qd = "";
for( int i = 0 ; i < lc ; i ++ )//分割输入的字符串
if( qc[i] == '=' )
{
for( int j = i + 1 ; j < lc ; j ++ )
qd = qd + qc[j];
qc.erase( i , lc - i );
}
//cout << qa << ' ' << qb << ' ' << qc << ' ' << qd << endl;
for( int i = 1 ; i <= k ; i ++ )
if( t[i] == qb )//确定所在的表格
{
for( int j = 1 ; j <= y[i] ; j ++ )
if( s[i][1][j] == qc )//确定要相同的关键字
{
for( int l = 2 ; l <= x[i] ; l ++ )
if( s[i][l][j] == qd )//确定关键字内容相同的信息
{
la = qa.size();
a = "";
for( int d = 0 ; d < la ; d ++ )//确定要输出的关键字
{
if( qa[d] == ',' )
{
for( int p = 1 ; p <= y[i] ; p ++ )//确定要输出的关键字的具体位置
if( s[i][1][p] == a )
{
cout << s[i][l][p] << ' ';
break;
}
a = "";
continue;
}
a = a + qa[d];
}
for( int p = 1 ; p <= y[i] ; p ++ )
if( s[i][1][p] == a )
{
cout << s[i][l][p] << ' ';
break;
}
cout << endl;
}
}
}
}
return 0;
}

浙公网安备 33010602011771号