这个题解26~31什么意思

P1603 斯诺登的密码

XSean @ 2022-08-17 17:12:37


#include<iostream>
#include<algorithm>
using namespace std;
string yw[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 sz[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 k;
int a[10];

int main()
{
    for(int i=1;i<=6;i++)
    {
        string x;
        cin>>x;//直接用变量读就行了
        for(int j=1;j<=26;j++)//26种英文数字
            if(yw[j]==x)
                {a[++k]=sz[j];break;}//k记录有几个英文数字
    }
    if(k==0){cout<<0<<endl;return 0;}//先判断一下句子中有没有英文数字
    sort(a+1,a+k+1);//排序//26
    for(int i=1;i<=k;i++)
    {
        if(i!=1&&a[i]<10)cout<<0;//补0
        cout<<a[i];
    }//31
    cout<<endl;
    return 0;
}

by 3a51_ @ 2022-08-17 17:31:18

行数?


by XSean @ 2022-08-17 17:32:08

@Tothetime_tolife 嗯对


by Always_Remember_It @ 2022-08-17 18:30:27

@Sean_xzx 26行排序


by Always_Remember_It @ 2022-08-17 18:32:31

@Sean_xzx 从大到小排序,然后从最大到最小枚举,当i=1也就是输出端第一个不用前导零,剩下的补零


by Always_Remember_It @ 2022-08-17 18:32:51

@zswmb 输出的


by XSean @ 2022-08-17 18:52:34

@zswmb 为什么要排序


by Always_Remember_It @ 2022-08-17 18:58:10

@Sean_xzx 讲错了,从小到大


by Always_Remember_It @ 2022-08-17 18:58:34

@Sean_xzx 把这些两位数按数位排成一行,组成一个新数,如果开头为 00,就去 00。


by XSean @ 2022-08-17 19:01:35

@zswmb 假如说9与16两个数从小到大排序输出916,但是169不是更小吗


by Always_Remember_It @ 2022-08-17 19:44:36

@Sean_xzx 那变成了1609吧


| 下一页