POJ 1023 The Fun Number System C++ 巧妙 背

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
//看博友好文章 抄博友程序 巧妙 背
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n;
		string s;
		s.clear();
		__int64 da;//抄博友程序
		int jg[100];
		memset(jg,0,sizeof(jg));
		int js=0;
		cin>>n>>s>>da;
		int tn=n;
		//cout<<n<<" "<<s<<" "<<da<<endl;
		__int64 ch=0;
		__int64 bas=1;
		__int64 jl=da;
		while(n--)
		{
			if(da&1)
			{
				if(s[n]=='n')
				{
					da++;//为了使数据不失真 
					ch=ch-bas;
				}else
				{
					ch=ch+bas;
				}
				jg[n]=1;//奇数最低位只能为一   
			}else
			{		
				jg[n]=0;
			}	
			da=da>>1;		
			bas=bas<<1;	
			//cout<<bas<<" "<<ch<<endl;		
		}
		//cout<<ch<<endl;
		//cout<<da<<endl;
		if(da==0)//抄博友程序 
		//if(ch==jl)//wa 
		{
			for(int i=0;i<tn;i++)
			{
				cout<<jg[i];
			}
			cout<<endl;
		}else
		{
			cout<<"Impossible"<<endl;
		}		
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值