标题:Safecracker的解决方案
只看楼主
hjwzlsc
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-7-23
结帖率:0
已结贴  问题点数:20 回复次数:6 
Safecracker的解决方案
大家好,我是个C语言新手,以下是我关于Safecracker的代码,在机上运行可以,可是怎么也不能AC呀,我怎么找都找不到问题呀,望哪位高手能指点一下,不胜感激!
#include<stdio.h>
#include<string.h>
void sort(char str[],int len)
{
    int i,j,k,t;
    for(i=0;i<len-1;i++)
    {
        k=i;
        for(j=i+1;j<len;j++)
        if(str[j]<str[k])
                k=j;
            t=str[k];
            str[k]=str[i];
            str[i]=t;
    }
}
   
int main()
{
    char str[12];
    long int target;
    int a[12] ;
    int v,w,x,y,z;
    int f1,f2,f3,f4,f5;
    int len;
    while(scanf("%d %s",&target,str)!=EOF)
    {
        
        if(target==0 && !strcmp(str,"END"))
                break;
        int count=0;
         len=strlen(str);
        sort(str,len);
        for(int i=0;i<len;i++)   
            a[i]=str[i]-64;
        for(v=0;v<i;v++)
        {
            for(w=0;w<i;w++)
            {
                if(w==v)
                    continue;
                for(x=0;x<i;x++)
                {
                    if(x==w || x==v)
                        continue;
                    for(y=0;y<i;y++)
                    {
                        if(y==x || y==w || y==v)
                            continue;
                        for(z=0;z<i;z++)
                        {
                            if(z==y ||z==x || z==w || z==v)
                                continue;
                            if(a[v]-a[w]*a[w]+a[x]*a[x]*a[x]-a[y]*a[y]*a[y]*a[y]+a[z]*a[z]*a[z]*a[z]*a[z]==target)
                            {
                                f1=v;
                                f2=w;
                                f3=x;
                                f4=y;
                                f5=z;
                                count++;
                            }
                        }
                    }
                }
            }
        }
        if(count==0)
            printf("no solution");
        else
            printf("%c%c%c%c%c%c",str[f1],str[f2],str[f3],str[f4],str[f5]);
        printf("\n");
    }
    return 0;
}
搜索更多相关主题的帖子: Safecracker 方案 Safecracker 方案 
2010-07-23 09:06
do8do8do8
Rank: 10Rank: 10Rank: 10
来 自:沙滩
等 级:贵宾
威 望:17
帖 子:366
专家分:1845
注 册:2010-7-2
得分:20 
楼主,你喜欢中国队吗
什么是AC?C.O.D!你真有钱
for(int i=0;i<len;i++)   
   a[i]=str[i]-64;
a[i]的范围:48<=a[i]<=57才能进行下面的计算。也就是字母输入在q---y之间
但是数字太大 我做了些修改  我改成了 a[i]=str[i]-64-48 这样子我能确定 a[i]里的内容在 0--9之内

所以当我输入 9 空格 yqqqq
的时候 我会得出有解的结果 因为 y-64-48=9  q-64-48=1 所以 9-1的平方+1的立方-1的四次方+1的五次方=9
结果会输出
yqqqq
(仅供参考)

[ 本帖最后由 do8do8do8 于 2010-7-23 10:12 编辑 ]

学C语言从底层开始,学编程从问题开始,一日学会C!!!
2010-07-23 09:53
hjwzlsc
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-7-23
得分:0 
谢谢了楼主,AC就是在OJ上能通过的意思。那个题目上要求是输入大写的26个字母,题目是这样的,望楼主能再指点指点,谢谢了
"The item is locked in a Klein safe behind a painting in the second-floor library. Klein safes are extremely rare; most of them, along with Klein and his factory, were destroyed in World War II. Fortunately old Brumbaugh from research knew Klein's secrets and wrote them down before he died. A Klein safe has two distinguishing features: a combination lock that uses letters instead of numbers, and an engraved quotation on the door. A Klein quotation always contains between five and twelve distinct uppercase letters, usually at the beginning of sentences, and mentions one or more numbers. Five of the uppercase letters form the combination that opens the safe. By combining the digits from all the numbers in the appropriate way you get a numeric target. (The details of constructing the target number are classified.) To find the combination you must select five letters v, w, x, y, and z that satisfy the following equation, where each letter is replaced by its ordinal position in the alphabet (A=1, B=2, ..., Z=26). The combination is then vwxyz. 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."

v - w^2 + x^3 - y^4 + z^5 = target

"For example, given target 1 and letter set ABCDEFGHIJKL, one possible solution is FIECB, since 6 - 9^2 + 5^3 - 3^4 + 2^5 = 1. There are actually several solutions in this case, and the combination turns out to be LKEBA. Klein thought it was safe to encode the combination within the engraving, because it could take months of effort to try all the possibilities even if you knew the secret. But of course computers didn't exist then."

=== Op tech directive, computer division, 2002/11/02 12:30 CST ===

"Develop a program to find Klein combinations in preparation for field deployment. Use standard test methodology as per departmental regulations. Input consists of one or more lines containing a positive integer target less than twelve million, a space, then at least five and at most twelve distinct uppercase letters. The last line will contain a target of zero and the letters END; this signals the end of the input. For each line output the Klein combination, break ties with lexicographic order, or 'no solution' if there is no correct combination. Use the exact format shown below."
以上是题目的要求
 
下面是给出几个输入输出的例子:
Sample Input
1 ABCDEFGHIJKL
11700519 ZAYEXIWOVU
3072997 SOUGHT
1234567 THEQUICKFROG
0 END
 

Sample Output
LKEBA
YOXUZ
GHOST
no solution
2010-07-23 12:29
do8do8do8
Rank: 10Rank: 10Rank: 10
来 自:沙滩
等 级:贵宾
威 望:17
帖 子:366
专家分:1845
注 册:2010-7-2
得分:0 
你发出贴之后 就可以AC了 你怎么AC不了? 出现什么问题?
想问一下 这个保险箱里面的秘密是什么?

学C语言从底层开始,学编程从问题开始,一日学会C!!!
2010-07-23 14:05
hjwzlsc
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-7-23
得分:0 
楼主可以AC吗,我是在杭州电子科技大学的OJ上做这个题目呀,我提交了多次了,它总是说" wrong answer",我也不知道问题出在哪里呀,至于保险箱里面的秘密嘛,我也不懂呀,望楼主告诉我你是在哪里AC的,谢了
2010-07-23 14:49
do8do8do8
Rank: 10Rank: 10Rank: 10
来 自:沙滩
等 级:贵宾
威 望:17
帖 子:366
专家分:1845
注 册:2010-7-2
得分:0 
回复 5楼 hjwzlsc
哦 我明白了 你瞧要什么要求吧 反复看那段英文 你可能会知道什么

你没给出范围的判断 如果随便输入怎么办? 你怎么处理 这个它有要求的啊 等等

[ 本帖最后由 do8do8do8 于 2010-7-23 15:51 编辑 ]

学C语言从底层开始,学编程从问题开始,一日学会C!!!
2010-07-23 15:42
hjwzlsc
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-7-23
得分:0 
我还是不太明白,希望楼主能将我的程序按你所说的修改修改,或者能在回复中写一个你所想的程序,非常感谢
2010-07-23 21:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-313776-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.747851 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved