文章
99
粉丝
120
获赞
8
访问
99.7k
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int getCnt(vector<string>& proxy, vector<string>& server, int m){
// index表示每次遍历 serve 时的起始下标
int index = 0, count = 0;
while(index < m){
int maxn = 0;//代表 index 右移的最大距离
// 遍历代理服务器
for(string ip : proxy){
int j = index;
while(j < m && ip != server[j]) j ++;
maxn = max(maxn, j - index);
}
if(maxn == 0) return -1;
count ++;
index += maxn;
}
return count - 1;
}
int main(){
int n, m;
while(cin >> n){
vector<string> proxy(n);
for(int i = 0; i < n; i ++){
cin >> proxy[i];
}
cin >> m;
vector<string> server(m);
for(int i = 0; i < m; i ++)
cin >> server[i];
cout << getCnt(proxy, server, m);
}
}
...
登录后发布评论
暂无评论,来抢沙发