POJ 1248 Safecracker G++

#include <iostream>
#include <cmath>
using namespace std;
//英语 抄博友程序 
int main()
{
	/*
	while(1)
	{
		string st;
		cin>>st;
		cout<<(st[0]-'A'+1)-pow((st[1]-'A'+1),2)+pow((st[2]-'A'+1),3)-pow((st[3]-'A'+1),4)+pow((st[4]-'A'+1),5)<<endl;		
	}*/
	while(1)
	{
		int x;
		string s;	
		cin>>x>>s;
		if(x==0 && s=="END")
		{
			break;
		}	
		int n=s.size();
		string jg="     ";
		for(int a=1;a<=n;a++)
		{
			for(int b=1;b<=n;b++)
			{
				for(int c=1;c<=n;c++)
				{
					for(int d=1;d<=n;d++)
					{
						for(int e=1;e<=n;e++)
						{
							int ta=s[a-1]-'A'+1;
							int tb=s[b-1]-'A'+1;
							int tc=s[c-1]-'A'+1;
							int td=s[d-1]-'A'+1;
							int te=s[e-1]-'A'+1; 
							if((ta-tb*tb+tc*tc*tc-td*td*td*td+te*te*te*te*te)==x &&
							a!=b && a!=c && a!=d && a!=e && b!=c && b!=d && b!=e && c!=d && c!=e && d!=e)
							{
								string t="     ";
								t[0]=s[a-1];
								t[1]=s[b-1];
								t[2]=s[c-1];
								t[3]=s[d-1];
								t[4]=s[e-1];
								if(jg=="     " || t>jg)
								{
									jg=t;
								}
								
							}
						}
					}
				}
			}
		}
		if(jg=="     ")
		{
			cout<<"no solution"<<endl;
		}else
		{
			cout<<jg<<endl;
		}		
	} 
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值