zoukankan      html  css  js  c++  java
  • poj-1248 Safecracker

    学长说 :多模仿,再形成自己的风格

    他的代码真的好好看,害/

     这个题,,贼暴力

    不过会用qsort了✌

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int compare(const void*min,const void*max)
    {
        return (*(int*)max>*(int*)min);
    }
    double char_2_int(char ch)
    {
        return ch-'A'+1;
    }
    int main()
    {
        double target;
        char upper[15];
        while(scanf("%lf%s",&target,upper)&&(target!=0||strcmp(upper,"END")!=0))
        {
            qsort(upper,sizeof(upper),sizeof(char),compare);
            int sum;
            int flag=0;
            char str[100];
            int i,j,k,l,m;
            for(i=0;upper[i];i++)
            {
                for(j=0;upper[j];j++)
                {
                    for(k=0;upper[k];k++)
                    {
                        for(l=0;upper[l];l++)
                        {
                            for(m=0;upper[m];m++)
                            {
                                if(i!=j&& i != k && i != l && i != m && j != k &&j != l && j != m && k != l && k != m && l != m)
                                {
                                   sum = char_2_int(upper[i]) - char_2_int(upper[j]) *
                                        char_2_int(upper[j]) + char_2_int(upper[k]) *char_2_int(upper[k]) *
                                        char_2_int(upper[k]) - char_2_int(upper[l]) *char_2_int(upper[l]) *
                                        char_2_int(upper[l]) *char_2_int(upper[l]) + char_2_int(upper[m]) *
                                        char_2_int(upper[m]) *char_2_int(upper[m]) *char_2_int(upper[m]) *
                                        char_2_int(upper[m]);
                                        if(sum == target)
                                        {
                                            flag = 1;
                                            str[0]=upper[i];
                                            str[1]=upper[j];
                                            str[2]=upper[k];
                                            str[3]=upper[l];
                                            str[4]=upper[m];
                                            break;
                                        }
                                }
                            }
                        }
                    }
                }
            }
        }
        if(flag == 1)
        {
            puts(str);
        }
            else printf("no solution
    ");
        }
        return 0;
    }
    Aim: Buaa
  • 相关阅读:
    python 3字符编码
    python 数据类型 datatype
    部署python django程序
    linux centos7安装python3
    关于mysql数据库优化
    关于bottle WEB框架中签名cookie的一点理解
    1111
    bottle框架剖析
    the difference __str__ and __repr__
    property getitem setitem
  • 原文地址:https://www.cnblogs.com/calm-blogme/p/11967067.html
Copyright © 2011-2022 走看看