HDU 2206 IP的计算 字符串

来源:互联网 发布:淘宝精仿 编辑:程序博客网 时间:2024/06/05 18:13

http://acm.hdu.edu.cn/showproblem.php?pid=2206

#include<iostream>#include<string>#include<cstring>#include<algorithm>#include<cstdio>#include<cmath>#include<cctype>#include<iomanip>using namespace std;const int inf=10000000;int main() {    char f[105];    while(gets(f)!=NULL) {        bool ok=true;        int p[100],k=0;        for(int i=0;f[i]&&ok;++i)            if(f[i]=='.') p[k++]=i;            else if(f[i]<'0'||f[i]>'9')ok=false;        if(k!=3)ok=false;///不是三个'.'        if(!p[0]||p[0]-0>3)ok=false;///两点之间超过三位        for(int i=1;i<k;++i)///            if(p[i]-p[i-1]>4||p[i]-p[i-1]==1)ok=false;///        int len=strlen(f);        int s=0;        for(int i=0;f[i];++i)            if(f[i]=='.'){                if(s>255)ok=false;                s=0;            }            else s=s*10+f[i]-'0';        if(s>255)ok=false;        if(ok)puts("YES");        else puts("NO");    }    return 0;}