小编Adi*_*jha的帖子

差异 b/w 使用 i<strlen() 和 str[i] != '\0'

当我使用时,for(i=0;i<strlen(s);i++)我收到时间限制超过错误。当我使用for(i=0;s[i]!='\0';i++)我的代码获得成功提交。为什么?

我还提供了来自 codechef 的问题链接 - https://www.codechef.com/problems/LCPESY

类型 1:

    for (i = 0; i < strlen(s1); i++) {
        f1[s1[i]]++;
    }
    for (i = 0; i < strlen(s2); i++) {
        f2[s2[i]]++;
    }
Run Code Online (Sandbox Code Playgroud)

类型 2:

    for (i = 0; s1[i] != '\0'; i++) {
        f1[s1[i]]++;
    }
    for (i = 0; s2[i] != '\0'; i++) {
        f2[s2[i]]++;
    }
Run Code Online (Sandbox Code Playgroud)

完整代码:

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

long int min(long int a, long int b) {
    if (a >= b) …
Run Code Online (Sandbox Code Playgroud)

c arrays string algorithm runtimeexception

1
推荐指数
1
解决办法
268
查看次数

标签 统计

algorithm ×1

arrays ×1

c ×1

runtimeexception ×1

string ×1