2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 Banana

签到题
50的规模,随便搞搞都能过,用stl的string的搜索直接做了

#include 
using namespace std;
typedef long long ll;
const int maxn = 50;
string monkey[maxn+5];
string place[maxn+5];
int n,m;
inline char b2c(int b) {
    return (char)(32+b);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while (t--) {
        cin>>n>>m;
        for (int i = 0;i <= maxn; ++i) {
            monkey[i].clear();
            place[i].clear();
        }
        int mi,b,p;
        for (int i = 0;i < n; ++i) {
            cin >> mi >> b;
            monkey[mi] += b2c(b);
        }
        for (int i = 0;i < m; ++i) {
            cin >> b >> p;
            place[p] += b2c(b);
        }
        size_t pos;
        for (int mi = 1; mi <= maxn; ++mi) {
            if (monkey[mi].empty())
                continue;
            for (int p = 1; p <= maxn; ++p) {
                pos = place[p].find_first_of(monkey[mi]);
                if (string::npos != pos) {
                    cout<<mi<<" "<<p<<"\n";
                }
            }
        }
        cout<<"\n";
    }
    return 0;
}

你可能感兴趣的:(Acm,网络预选赛,算法)