-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip.cpp
More file actions
29 lines (21 loc) · 905 Bytes
/
ip.cpp
File metadata and controls
29 lines (21 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <assert.h>
using namespace std;
// input d
long long A[4], B[4];
int main() {
// ifstream cin("input.txt");you want to read/write from files
// ofstream cout("output.txt");
assert(4 == scanf("%d.%d.%d.%d", &A[0], &A[1], &A[2], &A[3]));
assert(4 == scanf("%d.%d.%d.%d", &B[0], &B[1], &B[2], &B[3]));
// at this point, the arrays A and B contain four elements each with the individual IP octects
// for example: 192.168.1.1 creates an array [192, 168, 1, 1] with 192 at index 0
// insert your code here
unsigned long long int ans;
ans = (B[3] + B[2]*256 + B[1]*256*256 + B[0]*256*256*256) - (A[3] + A[2]*256 + A[1]*256*256 + A[0]*256*256*256) +1;
printf("%lld\n", ans); // print the result
return 0;
}