解题思路:
注意事项: 坑爹的题目
参考代码:
#include<iostream>
#include<string>
#include<algorithm>
#include<string.h>
using namespace std;
int f(string s){
if(!isdigit(s[0]))
return 0;
int t = 0;
for(int i=0; i<s.length(); i++)
if(!isdigit(s[i]))
return 0;
else
t = t*10 + s[i]-'0';
if(t>255)
return 0;
return 1;
}
int main(){
char s[100];
while(scanf("%s",s) != EOF){
string t;
int i=0;
int n = 4;
while(n--){
for(; i<strlen(s); i++)
if(s[i] != '.')
t += s[i];
else{
i++;
break;
}
if(!f(t))
break;
t = "";
}
if(n>=0)
cout<<'N'<<endl;
else
cout<<'Y'<<endl;
}
return 0;
}
0.0分
0 人评分