zoukankan      html  css  js  c++  java
  • P1603 斯诺登的密码-字符串加法的妙用

    传送门:https://www.luogu.org/problemnew/show/P1603

    题意:

    首先在给定的字符串中,找出特定的单词,把它转化成特定的数字,

    然后在这些数字中,找出排列结果最小的一种排列;

    思路:

    第一步就是打表就ok,第二步,可以用字符串加法结果的大小进行排序;

    遇到“找出所有排列方法中最小的一个数”,可能就要怎么做;

    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <vector>
    #include <string>
    #define pb push_back
    using namespace std;
    typedef long long ll;
    
    vector<string>q;
    bool cmp (string a,string b)
    {
        return a+b < b+a;
    }
    int main(){
        string s;
        while(cin>>s)
        {
            if(s=="one"||s=="a"||s=="another"||s=="first")q.pb("01");
            if(s=="two"||s=="both"||s=="second")q.pb("04");
            if(s=="three"||s=="third")q.pb("09");
            if(s=="four")q.pb("16");
            if(s=="five")q.pb("25");
            if(s=="six")q.pb("36");
            if(s=="seven")q.pb("49");
            if(s=="eight")q.pb("64");
            if(s=="nine")q.pb("81");
            if(s=="ten")q.pb("00");
            if(s=="eleven")q.pb("21");
            if(s=="twelve")q.pb("44");
            if(s=="thirteen")q.pb("69");
            if(s=="fourteen")q.pb("96");
            if(s=="fifteen")q.pb("25");
            if(s=="sixteen")q.pb("56");
            if(s=="seventeen")q.pb("89");
            if(s=="eighteen")q.pb("24");
            if(s=="nineteen")q.pb("61");
            if(s=="twenty")q.pb("00");
            //break;
            if(s[s.length()-1]=='.')break;
    
        }
        sort(q.begin(),q.end(),cmp);
        bool isout=false;
        bool canout=false;
        string a="";
         for(int i=0;i<q.size();i++)
            a+=q[i];
        for(int i=0;i<a.length();i++)
        {
            if(a[i]!='0') canout=true;
            if(a[i]=='0'&&!canout)continue;
            cout<<a[i];
            isout=true;
        }
        if(!isout)cout<<"0";
        cout<<endl;
        return 0;
    }
  • 相关阅读:
    推荐一款超棒的阅读App
    IntelliJ中的main函数和System.out.println()快捷键
    oracle中varchar2字段存入blob字段及blob转成varchar2
    闭包
    some of the properties associated with the solution could not be read解决方法
    Visual Studio 2010如何利用宏
    中高级程序员成长必备素质
    WORD小技巧
    de4dot 用法
    JavaScript学习记录
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/8684502.html
Copyright © 2011-2022 走看看