LightOj 1354 - IP Checking
// Verdict:: Accepted
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <cmath>
- #include <cctype>
- #include <set>
- #include <list>
- #include <stack>
- #include <queue>
- #include <algorithm>
- #define sf scanf
- #define pf printf
- #define L long
- #define LL long long
- #define N 10000
- #define nl puts("")
- #define MOD 10000000007
- #define pb push_back
- #define ps push
- #define clr clear
- #define bn begin()
- #define ed end()
- using namespace std;
- int main()
- {
- int tc,t;
- char ch1[10],ch2[10],ch3[10],ch4[10];
- sf("%d",&tc);
- for (t=1;t<=tc;t++)
- {
- int a,b,c,d;
- LL b1,b2,b3,b4;
- sf("%d.%d.%d.%d",&a,&b,&c,&d);
- sf("%lld.%lld.%lld.%lld",&b1,&b2,&b3,&b4);
- int s1=0,s2=0,s3=0,s4=0,p1,p2,p3,p4,len1,len2,len3,len4;
- sprintf(ch1,"%lld",b1);
- len1=strlen(ch1);
- p1=len1-1;
- sprintf(ch2,"%lld",b2);
- len2=strlen(ch2);
- p2=len2-1;
- sprintf(ch3,"%lld",b3);
- len3=strlen(ch3);
- p3=len3-1;
- sprintf(ch4,"%lld",b4);
- len4=strlen(ch4);
- p4=len4-1;
- for (int i=0;i<len1;i++)
- {
- s1+=(ch1[i]-48)*pow(2,p1);
- p1--;
- }
- for (int i=0;i<len2;i++)
- {
- s2+=(ch2[i]-48)*pow(2,p2);
- p2--;
- }
- for (int i=0;i<len3;i++)
- {
- s3+=(ch3[i]-48)*pow(2,p3);
- p3--;
- }
- for (int i=0;i<len4;i++)
- {
- s4+=(ch4[i]-48)*pow(2,p4);
- p4--;
- }
- if(s1==a and s2==b and s3==c and s4==d)
- {
- pf("Case %d: Yes\n",t);
- }
- else
- {
- pf("Case %d: No\n",t);
- }
- }
- return 0;
- }
Comments
Post a Comment