#include #include #include #include using namespace std; class IPv6 { public: IPv6(string const& ip); ~IPv6() {} friend ostream& operator<<(ostream& os, IPv6 const& ip); protected: virtual ostream& print(ostream& os) const; vector component; }; class IPv6_Abbr : public IPv6 { public: IPv6_Abbr(string const& ip) : IPv6(ip) {} private: ostream& print(ostream& os) const; }; IPv6::IPv6(string const& ip) : component(8, 0) { istringstream ip_ss(ip); unsigned int n; int i = 0; do { if ( ip_ss >> hex >> n && n <= 0xffff) component.at(i) = n; ip_ss.clear(); ip_ss.ignore(4, ':'); ++i; } while ( i < 8 ); } ostream& IPv6::print(ostream& os) const { os << setw(4) << setfill('0') << hex << component.at(0); for (unsigned i = 1; i < component.size(); ++i) { os << ':' << setw(4) << setfill('0') << component.at(i); } return os; } ostream& operator<<(ostream& os, IPv6 const& ip) { return ip.print(os); } ostream& IPv6_Abbr::print(ostream& os) const { if ( component.at(0) != 0 ) os << hex << component.at(0); for (unsigned i = 1; i < component.size(); ++i) { os << ':'; if ( component.at(i) != 0 ) os << hex << component.at(i); } return os; } int main() { string line; while ( getline(cin, line) ) { cout << IPv6(line) << " <==> " << IPv6_Abbr(line) << endl; } return 0; }