求编程问题答案~要求过程```

2024-11-06 12:30:56
推荐回答(2个)
回答1:

1.
var i,n,temp:longint;
num:int64;
a:array[1..2000000] of boolean;
begin
assign(input,'loose.in');reset(input);
assign(output,'loose.out');rewrite(output);

readln(n);
num:=1;
fillchar(a,sizeof(a),false);
for i:=1 to n do num:=num*2;

for i:=1 to num-1 do
begin
read(temp);
a[temp]:=true;
end;

for i:=1 to num-1 do
if not a[i] then
begin
writeln(i);
break;
end;

close(input);close(output);
end.

2.
var s:string;
sum,i,n,p:integer;
begin
assign(input,'szh.in');
assign(output,'szh.out');
readln(s);
num:=0;
for i:=1 to length(s) do
begin
val(s[i],n,p);
sum:=sum+n;
end;
writeln(sum);

close(input);close(output);
end.

回答2:

第一题什么意思都没有看懂,我做了第二题。

program gwzh;
var
txt1,txt2:text;
x:string;
a,i:integer;
key:longint;
begin
assign(txt1,'szh.in');
reset(txt1);
readln(txt1,x);
close(txt1);
a:=length(x);{转化字符串长度}
key:=0;
assign(txt2,'szh.out');
rewrite(txt2);
for i:=1 to a do{累计相加}
key:=key+ord(x[i])-48;
write(txt2,key);{输出}
close(txt2);
readln;
readln;
end.