肿莫办??

P1603 斯诺登的密码

王紫烨 @ 2018-12-22 21:52:06

#include<bits/stdc++.h>
using namespace std;
string word,sub="";
bool cho[7];
int num[7],tot=0;long long ans=1073741823;
string tolowercase(string a){
    for(int i=0;a[i]!='\0';++i){
        if('A'<=a[i]&&a[i]<='Z')a[i]+=32;
    }
    return a;
}
int check(string v){
    if(v=="a"||v=="another"||v=="one"||v=="first")return 1;
    if(v=="two"||v=="both"||v=="second")return 2;
    if(v=="three"||v=="third")return 3;
    if(v=="four")return 4;if(v=="five")return 5;
    if(v=="six")return 6;if(v=="seven")return 7;
    if(v=="eight")return 8;if(v=="nine")return 9;
    if(v=="ten")return 10;if(v=="eleven")return 11;
    if(v=="twelve")return 12;if(v=="thirteen")return 13;
    if(v=="fourteen")return 14;if(v=="fifteen")return 15;
    if(v=="sixteen")return 16;if(v=="seventeen")return 17;
    if(v=="eighteen")return 18;if(v=="nineteen")return 19;
    if(v=="twenty")return 20;//上面几行,平滑的曲线!! 
    return 0;
    //我爱打表 
}
void dfs(int dp,long long zhi){
    if(dp>=tot){
        ans=min(ans,zhi);
        return;
    }
    for(int i=0;i<tot;i++){
        if(!cho[i]){
            cho[i]=true;
            dfs(dp+1,zhi*100+num[i]);
            cho[i]=false;
        }
    }
}
int main(){
    getline(cin,word);
    for(int i=0;word[i]!='\0';i++){
        if(isalpha(word[i]))sub+=word[i];
        else{
            int k=check(tolowercase(sub));
            if(k){
                num[tot++]=k*k%100;
            }
            sub="";
        }
    }
    if(!tot){
        cout<<"0\n";
        return 0;
    }
    dfs(0,0);
    cout<<ans<<endl;
    return 0;
}

60分求助
#1 AC #2 AC #3 AC #4 WA #5 WA


|