1. (数字删除)下面程序的功能是将字符串中的数字字符删除后输出。请填空。(每空3分,共12分)
var
s:string;
len, i:integer;
function delnum(var s:string):integer;
Var
I, j: Integer;
begin
j:=1;
for i:=1 to length(s) do
if (s[i]<'0') or (s[i]>'9') then
begin
s[j]:=s[i];
inc(j) ;
end;
exit( j );
end;
begin
readln(s);
len:=delnum(s);
for i:=1 to len do
write( s[i] );
writeln;
end.
2. (最大子矩阵和)给出m行n列的整数矩阵,求最大的子矩阵和(子矩阵不能为空)。
输入第一行包含两个整数m和n,即矩阵的行数和列数。之后m行,每行n个整数,描述整个矩阵。程序最终输出最大的子矩阵和。(最后一空4分,其余3分,共16分)
const
SIZE=100;
var
matrix: array [1..SIZE, 1..SIZE] of integer;
rowsum: array [1..SIZE, 0..SIZE] of integer;
//rowsum[i, j]记录前i行前j个数的和
M,n, i, j, first, last, area, ans:integer;
begin
read(m, n);
for i := 1 to m do
for j:=1 to n do
read(matrix[i, j]);
ans:=matrix [1,1] ;
for i:=1 to m do
rowsum[i,0]:=0 ;
for i:=1 to m do
for j:=1 to n do
rowsum[i, j]:=_ rowsum[i,j-1]+matrix[i,j] ;
for first := 1 to n do
for last:=first to n do
begin
area:=0 ;
for i:=1 to m do
begin
area:=area+ rowsum[i,last]-rowsum[i,first-1] ;
if (area>ans) then
ans:=area;
if (area<0) then
area:=0;
end;
end;
writeln(ans);
end.