File tree Expand file tree Collapse file tree 2 files changed +45
-47
lines changed Expand file tree Collapse file tree 2 files changed +45
-47
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -19,56 +19,54 @@ The function takes a string s as its only argument .
19
19
20
20
**************************************************************************/
21
21
22
+ // SOLUTION (in C++):
22
23
23
- SOLUTION (in C++):
24
+ # include < bits/stdc++.h >
24
25
25
- #include < bits/stdc++.h>
26
-
27
- using namesapce std;
26
+ using namespace std ;
28
27
29
28
int isValid (string s)
30
29
{
31
- s += ' .' ;
32
- int countDots = 0 ;
33
- string str = " " ;
34
- for (int i = 0 ;i<s.length ();i++)
35
- {
36
- if (s[i] != ' .' )
37
- {
38
- if (s[i] >= 48 && s[i] <= 57 )
39
- str += s[i];
40
- else
41
- return 0 ;
42
- }
43
- if (s[i] == ' .' )
44
- {
45
- if (str[0 ] == ' .' && str.length () > 1 )
46
- return 0 ;
47
- stringstream obj (str);
48
- int x = 0 ;
49
- obj>>x;
50
- if (x<0 || x>255 )
51
- return 0 ;
52
- if (str.size () == 0 )
53
- return 0 ;
54
- countDots++;
55
- str = " " ;
56
- }
57
- if (countDots == 4 )
58
- return 1 ;
59
- else
60
- return 0 ;
30
+ s += ' .' ;
31
+ int countDots = 0 ;
32
+ string str = " " ;
33
+ for (int i = 0 ; i < s.length (); i++)
34
+ {
35
+ if (s[i] != ' .' )
36
+ {
37
+ if (s[i] >= 48 && s[i] <= 57 )
38
+ str += s[i];
39
+ else
40
+ return 0 ;
41
+ }
42
+ if (s[i] == ' .' )
43
+ {
44
+ if (str[0 ] == ' .' && str.length () > 1 )
45
+ return 0 ;
46
+ stringstream obj (str);
47
+ int x = 0 ;
48
+ obj >> x;
49
+ if (x < 0 || x > 255 )
50
+ return 0 ;
51
+ if (str.size () == 0 )
52
+ return 0 ;
53
+ countDots++;
54
+ str = " " ;
55
+ }
56
+ if (countDots == 4 )
57
+ return 1 ;
58
+ else
59
+ return 0 ;
60
+ }
61
61
}
62
-
63
-
64
- int main ()
65
- {
66
- string s;
67
- cin>>s;
68
- int k = isValid (s);
69
- if (k == 0 )
70
- cout<<" Valid" <<endl;
71
- else
72
- cout<<" Not Valid" <<endl;
73
- return 0 ;
74
- }
62
+ int main ()
63
+ {
64
+ string s;
65
+ cin >> s;
66
+ int k = isValid (s);
67
+ if (k == 0 )
68
+ cout << " Valid" << endl;
69
+ else
70
+ cout << " Not Valid" << endl;
71
+ return 0 ;
72
+ }
You can’t perform that action at this time.
0 commit comments