测试点3没过。。。求daniu分析ya

P1603 斯诺登的密码

·伍六柒 @ 2019-10-07 19:09:33

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char words[30][20]={"zero","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"};

int word[30]={0,1,4,9,16,25,36,49,64,81,00,21,44,
69,96,25,56,89,24,61,0,1,4,1,1,4,9};
char a[100];
int i,j;
int flag,p=1,b[10];;
int main()
{
for(int i=1;i<=6;++i)
{
cin>>a;
    for(int j=1;j<=26;++j)
    {
        if(!strcmp(a,words[j]))
        {
            b[p++]=word[j];
            break;
        }
    }
}
sort(b+1,b+p+1);
for(int u=1;u<=p;++u)
{
    if(flag){
        printf("%.2d",b[u]);

    }
    else {
    if(b[u])
    {
     printf("%d",b[u]);
                 flag=1;
}}
}
return 0;

}


by Lovable_Wind @ 2019-10-07 19:14:19

您还是转C++党吧


by ·伍六柒 @ 2019-10-07 20:27:41

@klssxbc0002 用cout好像没法两位输出,所以用的%.2d


by 小屁孩2号 @ 2019-10-13 13:51:18

@RNGzx 用setprecision不就好了嘛


by ·伍六柒 @ 2019-10-14 22:15:54

@小屁孩2号 没。。没听过


by 小屁孩2号 @ 2019-10-19 20:59:20

@RNGzx cout<<fixed<<setprecision(2)<<...,记得包含头文件iomanip


by michuancey @ 2019-11-11 14:59:37

第三个测试点是所有单词都没?️数字。答案是0,需要特判


by 刘安哲 @ 2019-12-13 16:33:10

第3个点需要特判,没任何数字,输出0,很坑……


by daiwenchang @ 2019-12-30 19:54:37

@刘安哲 一共有哪些英文数字?another算几?


by 刘安哲 @ 2019-12-31 06:46:33

@daiwenchang another就是1


by daiwenchang @ 2019-12-31 13:35:56

@刘安哲 谢谢


|