点#2#4#5过不去

P1603 斯诺登的密码

MornHus @ 2022-09-01 19:41:37

#include<bits/stdc++.h>
using namespace std;
string number[25]={" zero "," one "," two "," three "," four "," five "," six "," seven "," eight "," nine "," ten "," eleven "," twelve "," thirteen "," fourteen "," fifteen "," sixteen "," seventeen "," eighteen "," nineteen "," twenty "};
int main(){
    string a;
    int n[10],te=0,ans=0;
    getline(cin,a);
    a=' '+a;
    for(int i=0;i<a.length();i++){
        if(a[i]>='A'&&a[i]<='Z'){
            a[i]=tolower(a[i]);
        }
    }
    for(int i=0;i<=20;i++){
        int p=0;
        while(a.find(number[i],p)!=-1){
            n[te]=(i*i)%100;te++;
            p=a.find(number[i],p)+1;
        }
    }
    if(te==0){
        cout<<0;
        return 0;
    }
    sort(n,n+te);
    int flag=0;
    for(int i=0;i<te;i++){
        if(flag==1&&!n[i])continue; else if(flag==1&&n[i])flag=0;
        if(!n[i]&&i==0){
            flag=1;
            continue;
        }
        cout<<n[i];
    }
    return 0;
}

by TensorFlow_js @ 2022-09-01 19:49:49

@zjybb a both another first second third 也算数字,看题面。


by MornHus @ 2022-09-01 19:56:04

已经加入这些数字的识别并测试有效,但还是那几个点过不去


#include<bits/stdc++.h>
using namespace std;
string number1[5]={""," first "," second "," third "};
string number2[5]={""," a "," both "};
string number3[5]={""," another "};
string number[25]={" zero "," one "," two "," three "," four "," five "," six "," seven "," eight "," nine "," ten "," eleven "," twelve "," thirteen "," fourteen "," fifteen "," sixteen "," seventeen "," eighteen "," nineteen "," twenty "};
int main(){
    string a;
    int n[10],te=0,ans=0;
    getline(cin,a);
    a=' '+a;
    for(int i=0;i<a.length();i++){
        if(a[i]>='A'&&a[i]<='Z'){
            a[i]=tolower(a[i]);
        }
    }
    for(int i=0;i<=20;i++){
        int p=0;
        while(a.find(number[i],p)!=-1){
            n[te]=(i*i)%100;te++;
            p=a.find(number[i],p)+1;
        }
    }
    for(int i=1;i<=3;i++){
        int p=0;
        while(a.find(number1[i],p)!=-1){
            n[te]=(i*i)%100;te++;
            p=a.find(number1[i],p)+1;
        }
    }
    for(int i=1;i<=2;i++){
        int p=0;
        while(a.find(number2[i],p)!=-1){
            n[te]=(i*i)%100;te++;
            p=a.find(number2[i],p)+1;
        }
    }
    for(int i=1;i<=1;i++){
        int p=0;
        while(a.find(number3[i],p)!=-1){
            n[te]=(i*i)%100;te++;
            p=a.find(number3[i],p)+1;
        }
    }
    if(te==0){
        cout<<0;
        return 0;
    }
    sort(n,n+te);
    int flag=0;
    for(int i=0;i<te;i++){
        if(flag==1&&!n[i])continue; else if(flag==1&&n[i])flag=0;
        if(!n[i]&&i==0){
            flag=1;
            continue;
        }
        cout<<n[i];
    }
    return 0;
}

by xingcode @ 2022-11-27 14:38:24


#include<bits/stdc++.h>
using namespace std;
int s,l=1;
int t[10];
string a,b;
int main()
{
    for(int i=1;i<=6;i++)
    {
        cin>>b;
        if(b=="one"||b=="another"||b=="first"||b=="a")
        {
            t[l]=1;
            l++;
        }
        else if(b=="two"||b=="both"||b=="second")
        {
            t[l]=4;
            l++;
        }
        else if(b=="three"||b=="third")
        {
            t[l]=9;
            l++;
        }
        else if(b=="four")
        {
            t[l]=16;
            l++;    
        }
        else if(b=="five")
        {
            t[l]=25;
            l++;    
        }
        else if(b=="six")
        {
            t[l]=36;
            l++;    
        }
        else if(b=="seven")
        {
            t[l]=49;
            l++;    
        }
        else if(b=="eight")
        {
            t[l]=64;
            l++;    
        }
        else if(b=="nine")
        {
            t[l]=81;
            l++;    
        }
        else if(b=="eleven")
        {
            t[l]=21;
            l++;    
        }
        else if(b=="twelve")
        {
            t[l]=44;
            l++;    
        }
        else if(b=="thirteen")
        {
            t[l]=69;
            l++;    
        }
        else if(b=="fourteen")
        {
            t[l]=96;
            l++;    
        }
        else if(b=="fifteen")
        {
            t[l]=25;
            l++;    
        }
        else if(b=="sixteen")
        {
            t[l]=56;
            l++;    
        }
        else if(b=="seventeen")
        {
            t[l]=89;
            l++;    
        }
        else if(b=="eighteen")
        {
            t[l]=24;
            l++;    
        }
        else if(b=="nineteen")
        {
            t[l]=61;
            l++;    
        }
    }
    sort(t+1,t+l);
    long long s=0;
    for(int i=1;i<l;i++)
    {
        s=s*100+t[i];
    }
    cout<<s;
    return 0;
} 

|