题解 | #代理服务器#
代理服务器
http://www.nowcoder.com/practice/1284469ee94a4762848816a42281a9e0
#include<stdio.h>
#include<malloc.h>
using namespace std;
typedef struct ip{
int i1;
int i2;
int i3;
int i4;
bool operator ==(struct ip b){
if(i1==b.i1&&i2==b.i2&&i3==b.i3&&i4==b.i4){
return true;
}
return false;
}
}ip;
int main(){
int n,m;
int maxf=-1;
int i,j;
int count=0;
ip* ip1=(ip*)malloc(sizeof(ip)*1000);
ip* ip2=(ip*)malloc(sizeof(ip)*5000);
while(scanf("%d",&n)!=EOF){
for(i=0;i<n;i++){
scanf("%d.%d.%d.%d",&ip1[i].i1,&ip1[i].i2,&ip1[i].i3,&ip1[i].i4);
}
scanf("%d",&m);
for(i=0;i<m;i++){
scanf("%d.%d.%d.%d",&ip2[i].i1,&ip2[i].i2,&ip2[i].i3,&ip2[i].i4);
}
maxf=0;
count=0;
int s=0;
while(maxf<m){
for(i=0;i<n;i++){
for(j=s;j<m;j++){
if(ip1[i]==ip2[j]){
if(j>=maxf){
maxf=j;
break;
}
break;
}
}
if(j==m){goto out;}
}
s=maxf;
count++;
if(n==1){
count=-1;
goto out;
}
}
out:
printf("%d\n",count);
}
}