Start Time:2016-11-26 12:00:00 End Time:2016-11-26 17:00:00 Refresh Time:2016-11-28 17:00:52 Private
J -- Just for Fun
Time Limit:1s Memory Limit:64MByte
Submissions:1043Solved:89
DESCRIPTION
P=NP?
INPUT
First line contains a single integer T which denotes the number of test cases. For each test case, there is two numbers which denote N and P separated by a space.(0<=N<
231231,0<=P<
231231)The input data is no large than 1M.
OUTPUT
For each case, output the "Y" or "N" in a single line.
SAMPLE INPUT
21 123123 0
SAMPLE OUTPUT
YY
题意:判断p是否等于p*n
题解:根据题意可以知道当p==0||n==1时,p与n*p相等。但是由于该题数据较大,即p,n的值可以很大,所以应该用字符串来做这道题。同时,在该题中,n,p的值还有可能为小数,所以应该考虑里面去。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t,i,j,count,flag,scnt;
string N,P;
cin>>t;
while(t--)
{
flag=1;
cin>>N>>P;
for(i=0;i<P.length()&&flag;i++)
{
if(P[i]!='0'&&P[i]!='.')
flag=0;
}
if(flag)
cout<<"Y"<<endl;
else
{
flag=1;count=0;scnt=0;
for(i=0;i<N.length();i++)
{
if(N[i]=='1')
count++;
if(N[i]=='.')
scnt=1;
}
if(count!=1)
cout<<"N"<< endl;
else
{
for(i=0;1<N.length();i++)
{
if(N[i]=='1')
break;
}
if(scnt&&N[i+1]!='.') flag=0;
if(scnt==0&&i!=N.length()-1) flag=0;
if(flag)
cout<<"Y"<<endl;
else
cout<<"N"<<endl;
}
}
}
return 0;
}