P=PN?

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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值