简单题
View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
char st[30];
int target;
void work()
{
int len = strlen(st);
for (int i = len; i >= 0; i--)
for (int j = len; j >= 0; j--)
if (i != j)
for (int k = len; k >= 0; k--)
if (i != k && j != k)
for (int l = len; l >= 0; l--)
if (i != l && j != l && k != l)
for (int m = len; m >= 0; m--)
if (i != m && j != m && k != m && l != m)
if (target == st[i] - 'A' + 1 - (st[j]
- 'A' + 1) * (st[j] - 'A' + 1)
+ (st[k] - 'A' + 1) * (st[k]
- 'A' + 1) * (st[k]
- 'A' + 1) - (st[l]
- 'A' + 1) * (st[l] - 'A' + 1)
* (st[l] - 'A' + 1) * (st[l]
- 'A' + 1) + (st[m] - 'A' + 1)
* (st[m] - 'A' + 1) * (st[m]
- 'A' + 1) * (st[m] - 'A' + 1)
* (st[m] - 'A' + 1))
{
printf("%c%c%c%c%c\n", st[i],
st[j], st[k], st[l], st[m]);
return;
}
printf("no solution\n");
}
int main()
{
//freopen("t.txt", "r", stdin);
while (1)
{
scanf("%d%s", &target, st);
if (target == 0 && strcmp(st, "END") == 0)
break;
sort(st, st + strlen(st));
work();
}
return 0;
}