#13655: 不知道為何在Dev C++過得去,到頁面上救不行(已考慮10^100000問題,使用字串比較)


squaremelon (方形西瓜)


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n,i,j,max,Len1,Len2;
    char Num[3][100001];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
         for(j=0;j<3;j++)
        {
            memset(Num[j],'\0',sizeof(Num[j]));
        }
        max=0;
        for(j=0;j<3;j++)
        {
            scanf("%s",Num[j]);
        }
        for(j=1;j<3;j++)
        {
            Len1=strlen(Num[j]);
            Len2=strlen(Num[max]);
            if(Len1>Len2)
            {
                max=j;
            }else
            {
                if(strcmp(Num[j],Num[max])==1)
                {
                    max=j;
                }
            }
        }
    printf("%s",Num[max]);
    printf("\n");
    }
    return 0;
}

#13657: Re:不知道為何在Dev C++過得去,到頁面上救不行(已考慮10^100000問題,使用字串比較)


justinO__o (夜貓)


#include
#include
#include

int main()
{
    int n,i,j,max,Len1,Len2;
    char Num[3][100001];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
         for(j=0;j<3;j++)
        {
            memset(Num[j],'\0',sizeof(Num[j]));
        }
        max=0;
        for(j=0;j<3;j++)
        {
            scanf("%s",Num[j]);
        }
        for(j=1;j<3;j++)
        {
            Len1=strlen(Num[j]);
            Len2=strlen(Num[max]);
            if(Len1>Len2)
            {
                max=j;
            }else
            {
                if(strcmp(Num[j],Num[max])==1)
                {
                    max=j;
                }
            }
        }
    printf("%s",Num[max]);
    printf("\n");
    }
    return 0;
}


邏輯有點錯

if (len1 > len2) {

  max = j;

} else if (len == len2) {

  if (strcmp(Num[j], Num[max]) == 1) {

    max = j;

  }

}

才對

不然len1 < len2的時候也會strcmp

#14086: Re:不知道為何在Dev C++過得去,到頁面上救不行(已考慮10^100000問題,使用字串比較)


squaremelon (方形西瓜)


#include
#include
#include

int main()
{
    int n,i,j,max,Len1,Len2;
    char Num[3][100001];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
         for(j=0;j<3;j++)
        {
            memset(Num[j],'\0',sizeof(Num[j]));
        }
        max=0;
        for(j=0;j<3;j++)
        {
            scanf("%s",Num[j]);
        }
        for(j=1;j<3;j++)
        {
            Len1=strlen(Num[j]);
            Len2=strlen(Num[max]);
            if(Len1>Len2)
            {
                max=j;
            }else
            {
                if(strcmp(Num[j],Num[max])==1)
                {
                    max=j;
                }
            }
        }
    printf("%s",Num[max]);
    printf("\n");
    }
    return 0;
}


邏輯有點錯

if (len1 > len2) {

  max = j;

} else if (len == len2) {

  if (strcmp(Num[j], Num[max]) == 1) {

    max = j;

  }

}

才對

不然len1 < len2的時候也會strcmp


我改了之後還是沒過ㄟ

不管把strcmp後面的值是0是1

結果都一樣

不知道怎麼了

#14087: Re:不知道為何在Dev C++過得去,到頁面上救不行(已考慮10^100000問題,使用字串比較)


anandrewboy70900 (ShowTsai)


#include
#include
#include

int main()
{
    int n,i,j,max,Len1,Len2;
    char Num[3][100001];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
         for(j=0;j<3;j++)
        {
            memset(Num[j],'\0',sizeof(Num[j]));
        }
        max=0;
        for(j=0;j<3;j++)
        {
            scanf("%s",Num[j]);
        }
        for(j=1;j<3;j++)
        {
            Len1=strlen(Num[j]);
            Len2=strlen(Num[max]);
            if(Len1>Len2)
            {
                max=j;
            }else
            {
                if(strcmp(Num[j],Num[max])==1)
                {
                    max=j;
                }
            }
        }
    printf("%s",Num[max]);
    printf("\n");
    }
    return 0;
}


邏輯有點錯

if (len1 > len2) {

  max = j;

} else if (len == len2) {

  if (strcmp(Num[j], Num[max]) == 1) {

    max = j;

  }

}

才對

不然len1 < len2的時候也會strcmp


我改了之後還是沒過ㄟ

不管把strcmp後面的值是0是1

結果都一樣

不知道怎麼了


strcmp

改成>0