| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 572 人关注过本帖
标题:Safecracker的解决方案
取消只看楼主 加入收藏
hjwzlsc
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-7-23
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
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
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
hjwzlsc
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-7-23
收藏
得分:0 
楼主可以AC吗,我是在杭州电子科技大学的OJ上做这个题目呀,我提交了多次了,它总是说" wrong answer",我也不知道问题出在哪里呀,至于保险箱里面的秘密嘛,我也不懂呀,望楼主告诉我你是在哪里AC的,谢了
2010-07-23 14:49
hjwzlsc
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-7-23
收藏
得分:0 
我还是不太明白,希望楼主能将我的程序按你所说的修改修改,或者能在回复中写一个你所想的程序,非常感谢
2010-07-23 21:12
快速回复:Safecracker的解决方案
数据加载中...
 
   



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

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