对于20%的数据:1 ≤ n ≤ 10
对于60%的数据:1 ≤ n ≤ 1000
对于100%的数据: 1 ≤ n ≤ 100000,1 ≤T≤ 10
程序:
const
a:array['0'..'9']of longint=(6,2,5,5,4,5,6,3,7,6);
var
t,i,n,k,l,w:longint;
h:int64;
j:char;
zfc:ansistring;
begin
assign(input,'match.in');
reset(input);
assign(output,'match.out');
rewrite(output);
readln(t);
for i:=1 to t do
begin
read(n);
readln(zfc);
delete(zfc,1,1);
h:=0;
for k:=1 to length(zfc) do
h:=h+a[zfc[k]];
l:=0;w:=n;
while (2*w<=h)and(7*w>=h)and(l<=n)and(w>0)and(h>0) do
begin
inc(l);
for j:='9' downto '0' do
if (h-a[j]>=2*(w-1))and(7*(w-1)>=h-a[j])and(w>1)or(w=1)and(h=a[j])then
begin
dec(w);
h:=h-a[j];
write(j);
break;
end;
end;
writeln;
end;
close(input);
close(output);
end.