-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path0033.cpp
More file actions
38 lines (36 loc) · 700 Bytes
/
0033.cpp
File metadata and controls
38 lines (36 loc) · 700 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
30
31
32
33
34
35
36
37
38
// 0033.整数与IP地址间的转换
#include <iostream>
using namespace std;
int main()
{
unsigned long n;
int m[4], i;
string s;
while(getline(cin, s))
{
s += '.';
n = 0;
while(!s.empty())
{
i = s.find('.');
int tmp = stoul(s.substr(0,i));
n = (n<<8) | tmp;
s = s.substr(i+1);
}
cout << n << endl;
cin >> n;
getchar();
i = 0;
while(n != 0)
{
m[i++] = n%256;
n/=256;
}
for(int i = 3; i > 0; i--)
{
cout << m[i] << '.';
}
cout << m[0] << endl;
}
return 0;
}