5、
字符串的输入、输出:
字符串类型既可按数组方式输入、输出,也可直接输入、输出:
readln(s);writeln(s);
多个字符串输入时以回车作为数据间的分隔符;
每个readln语句只能读入一个字符串。
pascal字符串应用实例:
问题:
Pascal字符串处理:
读入两个字符串,输出:
1、出现在某字符串中至少一次的字母、数字
2、同时出现在二字符串中的字母、数字
3、出现在一字符串中,不在另一字符串中的字母、数字
4、不出现在任何字符串中的字母、数字
解答(程序代码),可以使用集合:
var
s,t:string;
a,b,c,e,f,g,h:set of char;
i:byte;
begin
readln(s);readln(t);
a:=[];b:=[];c:=['A'..'Z','0'..'9'];
for i:=1 to length(s) do a:=a+[upcase(s)];a:=a*c;
for i:=1 to length(t) do b:=b+[upcase(t)];b:=b*c;
e:=a+b;f:=a*b;g:=(a-b)+(b-a);h:=c-e;
for i:=1 to 255 do if chr(i) in e then write(chr(i));writeln;
for i:=1 to 255 do if chr(i) in f then write(chr(i));writeln;
for i:=1 to 255 do if chr(i) in g then write(chr(i));writeln;
for i:=1 to 255 do if chr(i) in h then write(chr(i));writeln;
end.
不知道你需不需要区分大小写.这里忽略了大小写,你可以通过去掉upcase和加上'a'..'z'来修改.