社区讨论
求助 全RE了 ,想不明白为什么会出现RE
P3879[TJOI2010] 阅读理解参与者 3已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo31n33v
- 此快照首次捕获于
- 2023/10/23 23:19 2 年前
- 此快照最后确认于
- 2023/10/23 23:19 2 年前
CPP
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e3 + 10;
int T , n , son[N][26] , idx;
vector<int> alls[N];
int insert(string str)
{
int p = 0;
for(int i = 0 ; i < str.size() ; ++i)
{
int u = str[i] - 'a';
if(!son[p][u]) son[p][u] = ++idx;
p = son[p][u];
}
return p;
}
int query(string str)
{
int p = 0;
// 20层
for(int i = 0 ; i < str.size() ; ++i)
{
int u = str[i] - 'a';
if(!son[p][u]) return 0;
p = son[p][u];
}
return p;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string str;
cin >> T;
for(int i = 1 ; i <= T ; ++i)
{
cin >> n;
while(n--)
{
cin >> str;
int t = insert(str);
alls[t].push_back(i);
}
}
cin >> n;
while(n --)
{
cin >> str;
int t = query(str);
if(t == 0) continue;
alls[t].erase(unique(alls[t].begin(), alls[t].end()), alls[t].end());
for(int i = 0 ; i < alls[t].size() ; ++i)
{
cout << alls[t][i] << ' ';
}
cout << endl;
}
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...