My USACO Analysis:Greedy Gift Givers

来源:互联网 发布:1463 端口号 编辑:程序博客网 时间:2024/05/22 12:36
To record the names,I used an array of string.And I used another one to save the numbers that should be printed out.This is also an 'sd hoc' problem-as easy as it could be!
program gift1(input,output);
var
  a:array[
1..2000]of string;
  b:array[
1..2000]of integer;
  i,j,k,l,n,m,x:integer;
  s,s1:
string;
begin
  assign(input,
'gift1.in');
  reset(input);
  assign(output,
'gift1.out');
  rewrite(output);
  
  readln(n);
  fillchar(a,
sizeof(a),0);
  fillchar(b,
sizeof(b),0);
  
for i:=1 to n do
    readln(a[i]);
  
for i:=1 to n do
  begin
    readln(s);
    
for j:=1 to n do if a[j]=s then k:=j;
    readln(m,l);
    
if (l<>0) and (m<>0) then
    begin
      b[k]:
=b[k]-m+m mod l;
      
for j:=1 to l do
      begin
        readln(s1);
        
for x:=1 to n do if s1=a[x] then b[x]:=b[x]+m div l;
      end;
    end
    
else
      
for j:=1 to l do readln;
  end;
  
for i:=1 to n do
  begin
    write(a[i],
' ');
    writeln(b[i]);
  end;
  
  close(input);
  close(output);
end.

To download this PASCAL source file: gift1.pas
原创粉丝点击