#include <bitset> #include <iostream> #include <bits/stdc++.h> using namespace std; string strip, ip1, ip2; bool ishefa(string st) { string str[4]; string token; istringstream ss(st); int i = 0; while (getline(ss, token, '.')) { str[i] = token; i++; } if (atoi(str[0].c_str()) == 0)return false; for (int i = 0; i < 4; i++) { if (atoi(str[i].c_str()) < 0 || atoi(str[i].c_str()) > 255) return false; } return true; } bool ishefa1(string st) { string token; istringstream ss(st); int i = 0; string tmp; while (getline(ss, token, '.')) { int num= atoi(token.c_str()); if(num>255 || num<0)return false; bitset<8> b(num); tmp+=b.to_string(); } int coun=0; for(int i=31;i>=0;i--){ if(tmp[i]=='1'){ coun=i; break; } } string s= tmp.substr(0,coun+1); coun=0; for(int i=0;i<s.size();i++){ if(s[i]=='1')coun++; } if(s.size()==coun)return true; else return false; } bool issim(string strip, string ip1, string ip2) { string str1[4], str2[4], str3[4]; string token; istringstream ss1(strip), ss2(ip1), ss3(ip2); int i = 0; while (getline(ss1, token, '.')) { str1[i] = token; i++; } i = 0; while (getline(ss2, token, '.')) { str2[i] = token; i++; } i = 0; while (getline(ss3, token, '.')) { str3[i] = token; i++; } for (int i = 0; i < 4; i++) { bitset<8> b1(atoi(str1[i].c_str())); bitset<8> b2(atoi(str2[i].c_str())); bitset<8> b3(atoi(str3[i].c_str())); string t1 = b1.to_string(), t2 = b2.to_string(), t3 = b3.to_string(); string m1 = "", m2 = ""; for (int j = 0; j < 8; j++) { if (t1[j] == '1' && t2[j] == '1')m1 += '1'; else m1 += '0'; if (t1[j] == '1' && t3[j] == '1')m2 += '1'; else m2 += '0'; } if (m1 != m2)return false; } return true; } int main() { while (cin >> strip >> ip1 >> ip2) { if (!ishefa1(strip) || !ishefa(ip1) || !ishefa(ip2) ) { cout << '1' << endl; //continue; } else if (issim(strip, ip1, ip2)) { cout << '0' << endl; } else cout << '2' << endl; } } // 64 位输出请用 printf("%lld")