40分求调

P1603 斯诺登的密码

junXstar @ 2024-07-14 10:26:43

a[7]定义时塞了一堆999是为了判断有没有数字 句末是否有标点也判断到了 自己生成了很多s输入也都是正确结果 只通过了#1和#3,我是蓝名今天数据下完了

#include <bits/stdc++.h>
using namespace std;
string s;
int a[7]={0,999,999,999,999,999,999};
string exp1[30]={"","one","two","three","four","five","six","seven",
"eight","nine","ten","elven","twelve","thirteen","fourteen","fifteen",
"sixteen","seventeen","eighteen","nineteen","twenty","a","both",
"another","first","second","third"}; 
int num[30]={0,1,4,9,16,25,36,49,64,81,0,21,44,69,96,25,56,89,24,61,0,
1,4,1,1,4,9};
int main()
{

    for(int i=1;i<=6;i++)
    {
        cin>>s;
        for(int j=1;j<=26;j++)
        {
            if((s==exp1[j]||s==exp1[j]+"."))
            {
                a[i]=num[j];
                break;
            }
        }

    }
    sort(a+1,a+7);
    if(a[1]==999)
    {
        cout<<0;
        return 0;
    }       
    bool flag=0;
    for(int i=1;i<=6;i++)
    {
        if((a[i]!=0||flag)&&a[i]!=999)
        {
            flag=1;
            cout<<a[i];
        }
     } 
    return 0;
}

by Fish_Love_Water @ 2024-07-14 10:32:59

@junXstar 懒得看了,这是我写的,你自己参考下把:

#include<bits/stdc++.h>
using namespace std;
map<string,string> mp;
string s1[25]={"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
string s2[25]={"","01","04","09","16","25","36","49","64","81","00","21","44","69","96","25","56","89","24","61","00"};
string s3[10]={"","a","both","another","first","second","third"};
string s4[10]={"","01","04","01","01","04","09"};
int cnt;
string s,an[20],ans;
int main(){
//  freopen("fj.in","r",stdin);
//  freopen("fj.out","w",stdout);
    for(int i=1;i<=20;i++) mp[s1[i]]=s2[i];
    for(int i=1;i<=6;i++) mp[s3[i]]=s4[i];
    while(cin>>s)
        if(!mp[s].empty()) cnt++,an[cnt]=mp[s];
    sort(an+1,an+cnt+1);
    for(int i=1;i<=cnt;i++) ans+=an[i];
    int i=0;
    while(ans[i]=='0') i++;
    if(ans.size()==0) cout<<0;
    else for(;i<=ans.size();i++) cout<<ans[i];
    return 0;
}

虽然我一点都不负责,但是我还是想要个关注


by icebear233 @ 2024-08-11 17:34:58

@junXstar 你在输出时没有注意个位数前要补0(开头除外)再看看题,题目给的很清楚(虽然我也栽在这了)


by icebear233 @ 2024-08-11 17:40:30

@junXstar 而且你在排序前没有给你的数平方取模....


by icebear233 @ 2024-08-11 17:40:46

建议仔细看看题干


|