Tuesday, July 28, 2015

1354 - IP Checking

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int T,a,b,c,d,e=1;
    char ip[40];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d.%d.%d.%d",&a,&b,&c,&d);
        getchar();
        scanf("%s",ip);
 
        int sum=0,i=0;
        for(int j=34; j>=27; j--)
            sum += (ip[j]-48)*pow(2,i++);
        if(sum != d)
        {
            printf("Case %d: No\n",e++);
            continue;
        }
 
        sum=0;
        i=0;
        for(int j=25; j>=18; j--)
            sum += (ip[j]-48)*pow(2,i++);
        if(sum != c)
        {
            printf("Case %d: No\n",e++);
            continue;
        }
 
        i=0;
        sum=0;
        for(int j=16; j>=9; j--)
            sum += (ip[j]-48)*pow(2,i++);
        if(sum != b)
        {
            printf("Case %d: No\n",e++);
            continue;
        }
 
        sum=0;
        i=0;
        for(int j=7; j>=0; j--)
            sum += (ip[j]-48)*pow(2,i++);
        if(sum != a)
        {
            printf("Case %d: No\n",e++);
            continue;
        }
        printf("Case %d: Yes\n",e++);
    }
    return 0;
}

No comments:

Post a Comment

Triathlon

Triathlon - CodeChef # include < bits/stdc++.h > using namespace std ; # define fi first # define se second # define mp ...