Safecracker ACM提交不成功,请帮我看下错误在什么地方。程序可以通过自己的机子。

来源:百度知道 编辑:UC知道 时间:2024/09/22 01:51:56
#include<iostream>
#include<string>
using namespace std;
int main(){
string str;
int h[14];
long target;
cin>>target;
cin>>str;
int count=0;
int result[5];
while(1){
if(target==0 && str=="END")
break;
int i=0;
for(;str[i]!='\0';i++)
h[i]=str[i]-64;
int a,b,c,d,e;
for(a=0;a<i;a++){
for(b=0;b<i;b++){
if(b==a)
continue;
for(c=0;c<i;c++){
if(c==a || c==b)
continue;
for(d=0;d<i;d++){
if(d==a || d==b || d==c)
continue;
for(e=0;e<i;e++){
if(e==a || e==b || e==c || e==d)
continue;
if(h[a]-h[b]*h[b]+h[c]*h[c]*h[c]-h[d]*h[d]*h[d]*h[d]+h[e]*h[e]*h[e]*h[e]*h[e]==target){
result[0]=a;
result[1]=b;
result[2]=c;
result[3]=d;
resu

题目里有句:If there is more than one solution then the combination is the one that is lexicographically greatest, i.e., the one that would appear last in a dictionary."
所以要去字典序最大的。
我在你的代码基础上改了下,A掉了。

#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main(){
char str[1000];
int h[14];
long target;

int result[5];
while(cin>>target>>str){
if(target==0 && !strcmp(str,"END"))
break;
int count=0;
int i=0;
int len=strlen(str);
sort(str,str+len);
for(;i<len;i++)
h[i]=str[i]-64;
int a,b,c,d,e;
for(a=0;a<i;a++){
for(b=0;b<i;b++){
if(b==a)
continue;
for(c=0;c<i;c++){
if(c==b)
continue;
for(d=0;d<i;d++){
if(d==c)
continue;
for(e=0;e<i;e++){
if(e==d)<