1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(int argc, char** argv) { int T, N, M; register char c[51]; register int i, test_case, answer; vector<string> g1, g2; vector<string>::iterator it1, it2; g1.reserve(100000); g2.reserve(100000); scanf("%d",&T); for(test_case = 1; test_case <= T; ++test_case) { g1.clear(); g2.clear(); answer = 0; scanf("%d %d",&N,&M); for(i=0;i<N;i++) { scanf("%s",&c); g1.push_back(string(c)); } for(i=0;i<M;i++) { scanf("%s",&c); g2.push_back(string(c)); } sort(g1.begin(),g1.end()); sort(g2.begin(),g2.end()); it1 = g1.begin(); it2 = g2.begin(); while(it1!=g1.end()&&it2!=g2.end()){ if(*it1==*it2){ ++it1; ++it2; ++answer; } else if(*it1>*it2) ++it2; else ++it1; } printf("#%d %d\n",test_case,answer); } return 0; }
|