pascal 单词统计

问题描述:

pascal 单词统计
单词统计(word count.pas)
Time Limit:1000MS Memory Limit:65536K
Total Submit:13
Accepted:2
Description
【问题描述】
一个句子,只含英文字母,单词间用空格或逗号作为分隔符.统计句子中的单词数,如果含有其他的字符,则只要求输出错误信息及错误类型.
含有大写字母——错误类型 error 1
数字(0-9)——错误类型 error 2
其他非法字符——错误类型 error 3
【输入文件】(xx.in)
一行字符,以空格或逗号作为一个单词的分界点
【输出文件】(xx.out)
如果该句正确,输出含有单词数;如果该句错误,输出所有错误类型;
【输入样例】1
It is a ,pig12!
【输出样例】1
error 1 2 3
【输入样例】2
it is a pig
【输出样例】2
4
Input
1个回答 分类:综合 2014-10-02

问题解答:

我来补答
var b:array[1..3] of boolean;
ss:array[1..50] of string;
s:string;
i,j,k,p:integer;
f:boolean;
begin
f:=true;
for i:=1 to 3 do
b[i]:=true;
readln(s);
for i:=1 to length(s) do
begin
if (ord(s[i]-1) in [97..122,32,44]) and (f)then
if (i=1)or(s[i]=' ')or(s[i]=',')then k:=k+1;
if ord(s[i]) in [48..58] then
begin b[1]:=false; f:=11; end;
if (ord(s[i]) in [65..91]true)and(ord(s[i]) in [97..122,32,44]true)and(ord(s[i]) in [48..58]true) then begin
b[3]:=false; f:=false; end;
if ord(s[i]) in [65..91]=true then begin b[2]:=false;f:=false; end;
if (s[i]' ')and(s[i]',')and(f=true)then ss[k]:=ss[k]+s[i];
end;
if ftrue then write('error ');
for i:=1 to 3 do
if b[i]true then write(i,' ');
if ftrue then halt;
write(k);
end.
再问: ord(s[i]-1)
出问题了
再答: ord(s[i]) in [..]没问题的,我试过,我运行是没问题
 
 
展开全文阅读
剩余:2000