唯手熟尔
自己贪心了半天,各种判断合法,都是差这差那。。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e4;
int main()
{
int a,b,c,d;
ll ct=scanf("%d.%d.%d.%d",&a,&b,&c,&d);
if(a>255||b>255||c>255||d>255||a<0||b<0||c<0||d<0)
{
//cout<<a<<" "<<b<<" "<<c<<" "<<d;
cout<<"Error"<<endl;
return 0;
}
if(ct!=4)
{
cout<<"Error"<<endl;
return 0;
}else
{
char ch=getchar();
if(ch!='\n')
{
cout<<"Error"<<endl;
return 0;
}
else{
printf("0x%02X%02X%02X%02X",a,b,c,d);
}
}
}