题目描述
输入一行单词序列,相邻单词之间由1个或多个空格间隔,请对应地计算各个单词的长度。
注意,如果有标点符号(如连字符,逗号),标点符号算作与之相连的词的一部分。没有被空格间开的符号串,都算作单词。
输入格式
一行单词序列,最少1个单词,最多300个单词,单词之间用至少1个空格间隔。单词序列总长度不超过1000。
输出格式
依次输出对应单词的长度,之间以逗号间隔。
样例
输入样例
She was born in 1990-01-02 and from Beijing city.
输出样例
3,3,4,2,10,3,4,7,5
问题代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[1001];
int n,s;
int main(){
gets(a);//输入
n=strlen(a);//长度
for(int i=0;i<n;i++)
{
if(a[i]==' ')
{
if(s>0)
printf("%d,",s);
s=0;
}
else
s++;
}
printf("%d",s);
return 0;
75 Wrong Answer
foo.cc: In function 'int main()':
foo.cc:8:2: warning: 'char gets(char)' is deprecated [-Wdeprecated-declarations]
gets(a);//输入
^
In file included from /usr/include/c++/5/cstdio:42:0,
from foo.cc:1:
/usr/include/stdio.h:638:14: note: declared here
extern char gets (char __s) __wur attribute_deprecated;
^
foo.cc:8:2: warning: 'char gets(char)' is deprecated [-Wdeprecated-declarations]
gets(a);//输入
^
In file included from /usr/include/c++/5/cstdio:42:0,
from foo.cc:1:
/usr/include/stdio.h:638:14: note: declared here
extern char gets (char __s) __wur attribute_deprecated;
^
foo.cc:8:8: warning: 'char gets(char)' is deprecated [-Wdeprecated-declarations]
gets(a);//输入
^
In file included from /usr/include/c++/5/cstdio:42:0,
from foo.cc:1:
/usr/include/stdio.h:638:14: note: declared here
extern char *gets (char *__s) __wur attribute_deprecated;
^
/tmp/cct61iLt.o: In function main': foo.cc:(.text+0xe): warning: the
gets' function is dangerous and should not be used.
识别到 4 个测试点。
状态 耗时 内存占用
#1 Accepted 2ms 256 KiB
#2 Wrong Answer 读取到 10,10,24,4,3,7,6...,应为 10,10,24,4,3,7,6...。 2ms 256 KiB
#3 Accepted 2ms 256 KiB
#4 Accepted 2ms 256 KiB
**
求改进