/ 科创班 /

记录详情

Wrong Answer

/in/foo.c: In function 'main':
/in/foo.c:21:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(s);
     ^~~~
In file included from /in/foo.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/in/foo.c:31:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
             if (i > max)
             ^~
/in/foo.c:33:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
                 maxp = cmp;
                 ^~~~
/in/foo.c:47:5: warning: 'maxp' may be used uninitialized in this function [-Wmaybe-uninitialized]
     printstr(maxp);
     ^~~~~~~~~~~~~~
/tmp/ccZZ1ffv.o: In function `main':
foo.c:(.text.startup+0xd): warning: the `gets' function is dangerous and should not be used.
# 状态 耗时 内存占用
#1 Wrong Answer 0ms 208.0 KiB
#2 Wrong Answer 0ms 196.0 KiB
#3 Wrong Answer 0ms 188.0 KiB
#4 Wrong Answer 0ms 204.0 KiB
#5 Wrong Answer 0ms 192.0 KiB
#6 Wrong Answer 0ms 188.0 KiB
#7 Wrong Answer 0ms 208.0 KiB
#8 Accepted 0ms 188.0 KiB
#9 Wrong Answer 0ms 192.0 KiB
#10 Wrong Answer 0ms 200.0 KiB

代码

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define N 100

void
printstr(char *p)
{
    while (!((*p == ' ') || (*p == '\0')))
    {
        putchar(*p);
        p++;
    }
}

int
main()
{
    char s[N+1], *p, *maxp, *cmp;
    int max = 0;
    gets(s);
    p = s;
    cmp = s; 
    for (int i=0;; p++)
    {
        
        if (isalpha(*p))
            i++;
        if (isspace(*p))
        {
            if (i > max)
                max = i;
                maxp = cmp;
            cmp = p + 1; 
            i = 0;
        }
        if (*p == '\0')
        {
            if (i > max)
            {
                max = i;
                maxp = cmp;
            }
            break;
        }
    }
    printstr(maxp);
    return 0;
}

信息

递交者
类型
递交
题目
7.10求最长单词
题目数据
下载
语言
C
递交时间
2018-10-26 12:51:24
评测时间
2018-10-26 12:51:24
评测机
分数
10
总耗时
8ms
峰值内存
208.0 KiB