File tree Expand file tree Collapse file tree 1 file changed +47
-2
lines changed Expand file tree Collapse file tree 1 file changed +47
-2
lines changed Original file line number Diff line number Diff line change 1
1
#include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+ #include <math.h>
2
5
#define MAX 16
6
+
7
+
8
+ int * splitIp (char * ip )
9
+ {
10
+ int i , j , * arr ;
11
+ int temp = 0 ;
12
+ arr = (int * )malloc ( 4 * sizeof (int ));
13
+
14
+ for (i = 0 , j = 0 ; i < strlen (ip ); i ++ ){
15
+ if (ip [i ] == '.' ){
16
+ arr [j ] = temp ;
17
+ temp = 0 ;
18
+ j ++ ;
19
+ }
20
+ else {
21
+ temp = temp * 10 + (ip [i ] - 48 );
22
+ }
23
+ }
24
+
25
+ arr [j ] = temp ;
26
+
27
+ return arr ;
28
+ }
29
+
30
+
3
31
int main ()
4
32
{
33
+ int i ;
5
34
char ip [MAX ];
6
- scanf ("%s" , )
7
- }
35
+ unsigned int res = 0 ;
36
+ scanf ("%s" , ip );
37
+
38
+ int * arr = splitIp (ip );
39
+
40
+ unsigned int a = arr [0 ] * pow (2 , 24 );
41
+ unsigned int b = arr [1 ] * pow (2 , 16 );
42
+ unsigned int c = arr [2 ] * pow (2 , 8 );
43
+ unsigned int d = arr [3 ] * pow (2 , 0 );
44
+
45
+ res = a + b + c + d ;
46
+
47
+ printf ("Result = %u" , res );
48
+
49
+ return 0 ;
50
+ }
51
+
52
+
You can’t perform that action at this time.
0 commit comments