Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. bool isDigit(char c);
  7.  
  8. int isRight(string s);
  9.  
  10. int main()
  11. {
  12. string IP;
  13. cin >> IP;
  14. cout << isRight(IP);
  15. return 0;
  16. }
  17.  
  18. bool isDigit(char c)
  19. {
  20. return '0' <= c && c <= '9';
  21. }
  22. int isRight(string s)
  23. {
  24. int len = s.size(), sum = 0;
  25. for (int i = 1; i < len - 1; i++);
  26. {
  27. if (s[i] == '.')
  28. {
  29. if (!(isDigit(s[i + 1]) && isDigit(s[i - 1]))) return 0;
  30. sum++;
  31. }
  32. }
  33. if (sum != 3) return 0;
  34. else return 1;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement