Recently I wrote a question about string search. The question is: give you a sequence of strings and then give another sequence of strings, find the number of strings in the first sequence that have not appeared in the second sequence, ignore the case.
For example:
First sequence:
Inkfish
Henry
Carp
Max
Jericho
The second sequence:
Carp
Max
Carp
Result: 3
First, convert the first sequence to lowercase, and then sort the first sequence. 2) use binary search to search for the second sequence to see if it has appeared in the first sequence:
# Include "stdafx. H"
# Include <iostream>
# Include <algorithm>
# Include <cstring>
# Include <string>
Using namespace STD;
String S1 [20000];
String S2 [20000];
Int flag [20001];
Int bfind (string S, int low, int high) {// binary lookup Function
Int L, h;
L = low;
H = high;
Int mid = (L + H)/2;
If (L> H)
Return-1;
If (S = S1 [Mid])
Return mid;
Else if (S> S1 [Mid])
Return bfind (S, Mid + 1, high );
Else
Return bfind (S, low, mid-1 );
}
Int main (){
Int n, m;
While (CIN> N & n! = 0 ){
Cin> m;
Int COUNT = 0;
Memset (flag, 0, sizeof (FLAG ));
For (INT I = 0; I <n; I ++ ){
Cin> S1 [I];
For (Int J = 0; j <S1 [I]. Length (); j ++) {// converts all characters to lowercase letters.
If (S1 [I] [J] <97)
S1 [I] [J] = S1 [I] [J] + 32;
}
}
Sort (S1, S1 + n );
For (INT I = 0; I <m; I ++ ){
Cin> S2 [I];
For (Int J = 0; j <S2 [I]. Length (); j ++) {// converts all characters to lowercase letters.
If (s2 [I] [J] <97)
S2 [I] [J] = S2 [I] [J] + 32;
}
}
For (Int J = 0; j <m; j ++ ){
Int A = bfind (s2 [J], 0, n-1 );
If (! =-1 & flag [a] = 0 ){
Count ++;
Flag [a] = 1;
}
}
Cout <(n-count) <Endl;
Count = 0;
}
Return 0;
}