Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main() {
  5. std::string st;
  6. unsigned int a;
  7. std::cin >> st;
  8. size_t pos = st.find('.');
  9. if (pos != std::string::npos) {
  10. a += stoul(st.substr(0, pos))*(256*256*256);
  11. st = st.substr(pos+1);
  12. a += stoul(st.substr(0, st.find('.')))*(256*256);
  13. st = st.substr(st.find('.') + 1);
  14. a += stoul(st.substr(0, st.find('.')))*256;
  15. st = st.substr(st.find('.') + 1);
  16. a += stoul(st);
  17. std::cout << a;
  18. } else {
  19. a = stoul(st);
  20. std::cout << a/(256*256*256) << '.';
  21. a %= 256*256*256;
  22. std::cout << a/(256*256) << '.';
  23. a %= 256*256;
  24. std::cout << a/256 << '.';
  25. a %= 256;
  26. std::cout << a;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement