zoukankan      html  css  js  c++  java
  • 洛谷P1603——斯诺登的密码(字符串处理)

    https://www.luogu.org/problem/show?pid=1603#sub

    题目描述

    2013年X月X日,俄罗斯办理了斯诺登的护照,于是他混迹于一架开往委内瑞拉的飞机。但是,这件事情太不周密了,因为FBI的间谍早已获悉他的具体位置——但这不是最重要的——最重要的是如果要去委内瑞拉,那么就要经过古巴,而经过古巴的路在美国的掌控之中。丧心病狂的奥巴马迫降斯诺登的飞机,搜查时却发现,斯诺登杳无踪迹。但是,在据说是斯诺登的座位上,发现了一张纸条。纸条由纯英文构成:Obama is a two five zero.(以"."结束输出,只有6个单词+一个句号,句子开头如没有大写亦为合法)这句话虽然有点无厘头,但是警官陈珺骛发现这是一条极其重要的线索。他在斯诺登截获的一台笔记本中找到了一个C++程序,输入这条句子后立马给出了相对应的密码。陈珺鹜高兴得晕了过去,身为警官的你把字条和程序带上了飞机,准备飞往曼哈顿国际机场,但是在飞机上检查的时候发现——程序被粉碎了!飞机抵达华盛顿只剩5分钟,你必须在这5分钟内编写(杜撰)一个程序,免受上司的10000000000%10大板。破译密码的步骤如下:

    (1)找出句子中所有用英文表示的数字(≤20),列举在下:

    正规:one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty

    非正规:a both another first second third

    (2)将这些数字平方后%100,如00,05,11,19,86,99。

    (3)把这些两位数按数位排成一行,组成一个新数,如果开头为0,就去0。

    (4)找出所有排列方法中最小的一个数,即为密码。

    输入输出格式

    输入格式:

    一个含有6个单词的句子。

    输出格式:

    一个整型变量(密码)。

    输入输出样例

    输入样例#1:
    Black Obama is two five zero .
    输出样例#1:
    425

    #include<bits/stdc++.h>
    using namespace std;
    long long thing[6]={0},c=0;
    //直接打表判断
    void readchar(string &a)
    {
        if(a=="one" || a=="a" || a=="another" || a=="first"){thing[c]=1;c++;}
        else if(a=="two" || a=="both" || a=="second"){thing[c]=4;c++;}
        else if(a=="three" || a=="third"){thing[c]=9;c++;}
        else if(a=="four"){thing[c]=16;c++;}
        else if(a=="five"){thing[c]=25;c++;}
        else if(a=="six"){thing[c]=36;c++;}
        else if(a=="seven"){thing[c]=49;c++;}
        else if(a=="eight"){thing[c]=64;c++;}
        else if(a=="nine"){thing[c]=81;c++;}
        else if(a=="eleven"){thing[c]=21;c++;}
        else if(a=="twelve"){thing[c]=44;c++;}
        else if(a=="thirteen"){thing[c]=69;c++;}
        else if(a=="forteen"){thing[c]=96;c++;}
        else if(a=="fifteen"){thing[c]=25;c++;}
        else if(a=="sixteen"){thing[c]=56;c++;}
        else if(a=="seventeen"){thing[c]=89;c++;}
        else if(a=="eighteen"){thing[c]=24;c++;}
        else if(a=="nineteen"){thing[c]=61;c++;}
    }
    int main()
    {
        string str[6];
        for(int i=0;i<6;i++)
        cin>>str[i];
        for(int i=0;i<6;i++)
        {
            int j=str[i].find('.',0);//ind(char c,int pos);从pos开始查找字符c在当前字符串的位置
            if(j>=0)
                str[i]=str[i].erase(j,1);//erase(int pos,int n); 删除从pos开始的n个字符,比如erase(0,1)就是删除第一个字符
            readchar(str[i]);
        }
        sort(thing,thing+c);
        long long sum=0;
        for(int i=0;i<c;i++)
        {
            sum=sum*100+thing[i];
        }
        cout<<sum;
        return 0;
    }
  • 相关阅读:
    Bit Calculation
    Create ArcGIS maps in Power BI Desktop
    Power Apps visual for Power BI
    Create Power BI visuals by using Python
    运行 R 脚本
    Introduction to ASP.NET Core Blazor
    Tips and tricks for color formatting in Power BI
    Sharepoint Create, Update, and Delete List Items
    Power BI Office Online Server
    jQuery Organization Chart
  • 原文地址:https://www.cnblogs.com/YingZhixin/p/6500709.html
Copyright © 2011-2022 走看看