虽然题目停水的,但是好像字符处理运用的还比较合适
#include <iostream>
#include <string>
#include <cstdio>
#include <map>
using namespace std;
string Getstr(string str){///规格化字符串(添加0)
string temp,getstr="";
int itl=0,itf=str.find(".");
for(int i=0; i<3; i++){
temp = str.substr(itl,itf-itl);
temp.insert(0,3-temp.length(),'0');
getstr+=temp;
itl=itf+1,itf=str.find(".",itf+1);
}
temp = str.substr(itl,str.length()-itl);
temp.insert(0,3-temp.length(),'0');
getstr+=temp;
return getstr;
}
int main (){
int t,xx=0;
cin>>t;
while(t--){
int m,n,coun=0;
cin>>m>>n;
string str,tab[1005];
for(int i=0; i<m; i++){
cin>>str;
tab[coun++]=Getstr(str);
}
printf("Case #%d:
",++xx);
for(int i=0; i<n; i++){
cin>>str;
string temp = Getstr(str);
map<long long ,int > m;
for(int j=0; j<coun; j++){
long long sum=0;
for(int i=0; i<4; i++){
int aa=(tab[j][i*3]-'0')*100+(tab[j][i*3+1]-'0')*10+tab[j][i*3+2]-'0',bb=(temp[i*3]-'0')*100+(temp[i*3+1]-'0')*10+temp[i*3+2]-'0';
sum=sum*1000+(aa&bb);
}
m[sum]=0;
}
cout<<m.size()<<endl;
}
}
return 0;
}