IP computing------hdoj Hangzhou 2206 (after writing the brain hole open, imagination should be rich enough)

Source: Internet
Author: User

Problem description in the online course, I learned a lot about IP knowledge. IP name is called the Internet Protocol, and sometimes we use IP to refer to our IP network address, now IPV4 under a 32-bit unsigned integer to represent, the general point of view to display, the IP address is divided into 4 parts, each part is 8 bits, expressed as an unsigned integer (so do not need to appear with a positive sign), As 192.168.100.16, we are very familiar with the IP address, an IP address string no space appears (because to be represented as a 32 number).
But careless of me, often write the IP address wrong, now need you to use the program to judge.

Input has multiple case, one row per case and no more than 100 characters.
Output for each case, determine if the IP entered is correct, if yes is entered correctly, otherwise No.
Sample Input
192.168.100.16

Sample Output
YES
This question really really is super challenge a person's imagination!!!!!! After writing has been kneeling!!!!!! Sum up: 1. There must be no space at first 2. Then there are three decimal points 3. The beginning and end of the decimal point cannot be 4. The decimal point cannot be 5. The number of two decimals cannot be more than 255, which can be equal to 255, because 2 is 8, 256, but counting starts from 0, so the maximum is 2556. .000.000yes0.0.0.0yes010.00.00.00yes255.256.255.255no look at these groups. But there is a situation I did not consider, but the code AC, test data should not have this situation, so I do not dare to judge the right and wrong 0000.0.0.0 this has a The number of digits in the interval is greater than 3, and according to test instructions, it is impossible to infer right or wrong, so let's put it, but there is no such example of test data. Actually this kind of brain hole big open topic Hangzhou Electricity really is many, recently has been looking for.
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include < cmath>using namespace std; #define MAXN 10000 + 6char Six[maxn];char xp[maxn];int liu[maxn];int calcu (char s[]) {int    Len=strlen (s);    int sum=0;    for (int i=0;i<len;i++) {sum=sum*10+ (s[i]-' 0 '); } return sum;}    int main () {int i,j,k;    int t,n,m;    int a,b,c;        while (gets (six)!=null) {int Len=strlen (six); if (len<7| |            LEN&GT;15)///min and max length {printf ("no\n");        Continue } if (six[0]== '. ' | |        six[len-1]== '. ')            Determine the tail and the dot {printf ("no\n");        Continue        } int flag=1; for (i=0;i<len;i++)///whether there is a space {if (six[i]== ') {flag=                0;            Break            }} if (flag==0) {printf ("no\n");        Continue } for(i=0;i<len;i++)///Determine if there is a non-numeric character {if (six[i]< ' 0 ' | | |            Six[i]> ' 9 ') &&six[i]!= '. ')                {flag=0;            Break             }} if (flag==0) {printf ("no\n");        Continue        } m=0;                for (i=0;i<len;i++)///Find dot number {if (six[i]== '. ')        m++;            } if (m!=3) {printf ("no\n");        Continue        } m=0;                for (i=0;i<len;i++)///Find dot position {if (six[i]== '. ')        Liu[m++]=i; }/**if (liu[0]>3| |            len-1-liu[2]>3) {printf ("no\n");        Continue } if (liu[1]-liu[0]>4| | liu[1]-liu[0]==1| | liu[2]-liu[1]>4| |            Liu[2]-liu[1]==1) {printf ("no\n");        Continue        }*/Char l1[6]={},l2[6]={},l3[6]={},l4[6]={};    flag=0;    for (i=0;i<liu[0];i++) {l1[flag++]=six[i];        } flag=0;        for (i=liu[0]+1;i<liu[1];i++) {l2[flag++]=six[i];        } flag=0;        for (i=liu[1]+1;i<liu[2];i++) {l3[flag++]=six[i];        } flag=0;        for (i=liu[2]+1;i<len;i++) {l4[flag++]=six[i];        }///printf ("%s\n", six);        printf ("%d%d%d\n", liu[0],liu[1],liu[2]);        printf ("%s\n%s\n%s\n%s\n", L1,L2,L3,L4);        flag=0; if (CALCU (L1) >255| | CALCU (L2) >255| | CALCU (L3) >255| |        CALCU (L4) >255) flag=1;            if (flag) {printf ("no\n");        Continue    } printf ("yes\n"); } return 0;}

IP computing------hdoj Hangzhou 2206 (after writing the brain hole open, imagination should be rich enough)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.