#include "stdio.h" int main() { const int max = 255; const int cnt = 4; int ip[3][cnt]; int i,j; int next[3] = {1,2,0}; int out; while(scanf("%d.%d.%d.%d", &ip[i][0],&ip[i][1],&ip[i][2],&ip[i][3]) != EOF) { if(i == 2) { out = 0;//set to same for(j = 0;j<cnt;j++) { if((ip[0][j] > max) || (ip[1][j] > max)||(ip[2][j] > max) || (ip[0][j] < 0) || (ip[1][j] < 0)||(ip[2][j] < 0) || ((ip[0][j] != 255) && (j<3) &&(ip[0][j+1] != 0)) ) { out = 1; break; } if((ip[0][j] & ip[1][j]) != (ip[0][j] & ip[2][j])) { out = 2;//no break to check ip validation } } printf("%d\n", out); } i = next[i]; } return 0; }