题目描述
给定一个由英文字符、数字、空格和英文标点符号组成的字符串,长度不超过2000,请将其切分为单词,要求去掉所有的非英文字母,每行输出一个单词。
例如有文本:Python was created in 1990 by Guido van Rossum at Stichting Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands.
处理完成之后得到以下单词:
Python
was
created
in
by
Guido
van
Rossum
at
Stichting
Mathematisch
Centrum
CWI
see
http
www
cwi
nl
in
the
Netherlands
问题:在编程训练系统中测评完成率只有10%,我在VS上运行时得出的结果是正常的,想知道是哪里出的问题。********
我的代码:
#include"stdio.h"
int hanshu(char ch)
{
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
return 1;
}
else
{
return 0;
}
}
int main()
{
char ch[2000];
fgets(ch, 2000, stdin);
int i = 0;
int flag = 0;
int f = 1;
while (ch[i] != '\n')
{
if (hanshu(ch[i])==1)
{
printf("%c", ch[i]);
f = 0;
}
else if(f==0&&hanshu(ch[i])==0)
{
flag = 1;
}
if (flag == 1 && f == 0)
{
if (ch[i + 1] != '\n')
{
printf("\n");
flag = 0;
f = 1;
}
}
i++;
}
return 0;
}