- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdlib.h>
typedef std::ios_base& sibr;
typedef sibr (*StringType)(sibr);
int atoi_hod(const char a[], short int *offset)
{
short int numtype = (a[0]== '0')+((a[1]=='x')||(a[1]=='X'));
StringType st;
*offset = 0;
while(a[*offset]&&a[*offset]!='.') (*offset)=(*offset)+1;
switch (numtype)
{
case 0:
st = std::dec;
break;
case 1:
st = std::oct;
break;
case 2:
st = std::hex;
break;
}
int u;
std::istringstream(a)>>st>>u;
return u;
}
bool isIpv4String(const std::string &str)
{
size_t size = str.length();
bool result = size!=0;
if(result)
{
const char *c_str = str.c_str();
unsigned long int i = 0;
char sym;
do
{
sym = c_str[i++];
result = sym=='.'||(sym>='0'&&sym<='9')||!sym||(sym>='a'&&sym<='f')||(sym>='A'&&sym<='F')||sym=='x'||sym=='X';
}
while (sym&&result);
i = 0;
short int dotsOrTerm = 0, numbers = 0, offset;
while (result&&i<size)
{
int n = atoi_hod(&c_str[i], &offset);
result = n<256;
numbers += result;
i += offset;
result = result&&(c_str[i]=='.'||!c_str[i]);
i+=result;
dotsOrTerm += result;
}
result = (dotsOrTerm == 4)&&(numbers == 4);
}
return result;
}
int main()
{
std::string adress;
std::cin>>adress;
std::cout<<(isIpv4String(adress)?"TRUE":"FALSE")<<std::endl;
return 0;
}
Steve_Brown 09.04.2018 17:28 # 0
Xx7F.0.0.9х01
Psionic 09.04.2018 18:35 # 0
Steve_Brown 09.04.2018 19:48 # 0
Хотел сказать
Xx177.0.0.9х01
Это, кажется, по данной программе должно быть валидным.