/ 科创班 /

记录详情

Accepted

/in/foo.c: In function 'main':
/in/foo.c:11:1: warning: 'gets' is deprecated [-Wdeprecated-declarations]
 gets(line);
 ^~~~
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: In function 'longest':
/in/foo.c:50:7: warning: 'point' may be used uninitialized in this function [-Wmaybe-uninitialized]
 return(place);
       ^
/tmp/cc1Ehnpy.o: In function `main':
foo.c:(.text.startup+0x9): warning: the `gets' function is dangerous and should not be used.
# 状态 耗时 内存占用
#1 Accepted 2ms 256.0 KiB
#2 Accepted 3ms 256.0 KiB
#3 Accepted 2ms 256.0 KiB
#4 Accepted 2ms 256.0 KiB
#5 Accepted 6ms 256.0 KiB
#6 Accepted 1ms 256.0 KiB
#7 Accepted 2ms 256.0 KiB
#8 Accepted 2ms 256.0 KiB
#9 Accepted 2ms 256.0 KiB
#10 Accepted 1ms 256.0 KiB

代码

#include <stdio.h>
#include <string.h>
int main()
{
int alphabetic(char);
int longest(char []);
int i;
char line[100];

//printf("input one line:\n");
gets(line);
//printf("The longest word is :");
for(i=longest(line);alphabetic(line[i]);i++)
      printf("%c",line[i]);
//printf("\n");
return 0;
}

int alphabetic(char c)
{
if ((c>='a' && c<='z')||(c>='A'&&c<='z'))
    return(1);
else
    return(0);
}

int longest(char string[])
{
int len=0,i,length=0,flag=1,place=0,point;

for(i=0;i<=strlen(string);i++)
    if(alphabetic(string[i]))
       if(flag)
			{
			point=i;
			flag=0;	
			}
		else
			len++;
    else
		{
		flag=1;
		if(len>=length)
		{
		length=len;
		place=point;
		len=0;
		}
		}
return(place);
}

信息

递交者
类型
递交
题目
7.10求最长单词
题目数据
下载
语言
C
递交时间
2018-07-13 17:27:19
评测时间
2018-07-13 17:27:19
评测机
分数
100
总耗时
28ms
峰值内存
256.0 KiB