求助

P1603 斯诺登的密码

YuuAnn @ 2024-12-20 13:10:51

得分是40,找不到问题所在。
测试点下载量用完了。。。。

#include<stdio.h>
#include<string.h>
int main()
{
    char text [20];
    int n=0;
    while(scanf("%s",text)&&text[0]!='.'){
        if(memcmp(text,"another",6)==0){
            printf("1");
            n++;
        }
        if(memcmp(text,"one",3)==0){
            printf("1");
            n++;
        }
        if(memcmp(text,"two",3)==0){
            printf("4");
            n++;
        }
        if(memcmp(text,"three",3)==0){
            printf("9");
            n++;
        }
        if(memcmp(text,"four",3)==0){
            printf("16");
            n++;
        }
        if(memcmp(text,"five",3)==0){
            printf("25");
            n++;
        }
        if(memcmp(text,"six",3)==0){
            printf("36");
            n++;
        }
        if(memcmp(text,"seven",3)==0){
            printf("49");
            n++;
        }
        if(memcmp(text,"eight",3)==0){
            printf("64");
            n++;
        }
        if(memcmp(text,"nine",3)==0){
            printf("81");
            n++;}
        if(memcmp(text,"ten",3)==0){
            printf("00");
            n++;}
        if(memcmp(text,"eleven",3)==0){
            printf("21");
            n++;}
        if(memcmp(text,"twelve",3)==0){
            printf("44");
            n++;}
        if(memcmp(text,"thirteen",3)==0){
            printf("69");
            n++;}
        if(memcmp(text,"fourteen",3)==0){
            printf("96");
            n++;}
        if(memcmp(text,"fifteen",3)==0){
            printf("25");
            n++;}
        if(memcmp(text,"sixteen",3)==0){
            printf("56");
            n++;}
        if(memcmp(text,"seventeen",3)==0){
            printf("89");
            n++;}
        if(memcmp(text,"eighteen",3)==0){
            printf("24");
            n++;}
        if(memcmp(text,"nineteen",3)==0){
            printf("61");
            n++;}
        if(memcmp(text,"twenty",3)==0){
            printf("00");
            n++;}   
        }   
    if(n==0)
    printf("0");
    return 0;   
}

by MingDynasty @ 2024-12-20 14:09:51

你看可不可以这样写

#include<bits/stdc++.h>
using namespace std;
char dic[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 di[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};
unsigned long long int a[10],top,flag;
int i,j;
char s[129];
int main()
{
     for(i=1;i<=6;i++)
     {
          scanf("%s",s);
          for(j=1;j<=26;j++)
          {
               if(!strcmp(s,dic[j]))
               {
                    a[++top]=di[j];
                    break;
               }
          }
      }
      sort(a+1,a+top+1);
      for(i=1;i<=top;i++)
      {
           if(flag)
           {
                printf("%.2d",a[i]);
           }
           else
           {
                if(a[i])
                { 
                     printf("%d",a[i]);
                     flag=1;
                }
            }
     }
     if(!flag) printf("0");
     return 0;
}

by MingDynasty @ 2024-12-20 14:10:53

你写的代码忽略了a,both等特殊情况


by MingDynasty @ 2024-12-20 14:11:40

并且还没有排序


by MingDynasty @ 2024-12-20 14:12:13

这么写是可以把这些问题盖掉的


by MingDynasty @ 2024-12-20 14:12:42

而且关于下载量这个问题


by MingDynasty @ 2024-12-20 14:13:12

你可以通过刷题来提高次数


by MingDynasty @ 2024-12-20 14:13:45

有时题目中的特殊数据你可以写暴力


by MingDynasty @ 2024-12-20 14:14:23

从特殊到普通数据


by MingDynasty @ 2024-12-20 14:15:16

对于打比赛也是一个好的促进,你说呢?@YuuAnn


by YuuAnn @ 2024-12-20 17:49:32

@MingDynasty 大佬说得对,感谢大佬指点,大佬费心了。orz。


|