注意阅读题设:Each person sets aside a certain amount of money to give and divides this money evenly among all those to whom he or she is giving a gift. No fractional money is available, so dividing 3 among 2 friends would be 1 each for the friends with 1 left over -- that 1 left over stays in the giver's "account".

find函数用于根据名字寻找编号(2<=np<=10,才第二题呢,打什么哈希表…)。

Gift1
var n,i,j,money,sh:integer;
    s:string;
    c:array[1..10] of string;
    account:array[1..10] of longint;
function find(s:string):integer;
var i:integer;
begin
  for i:=1 to n do
    if c[i]=s then exit(i);
end;
begin
  assign(input,'gift1.in');reset(input);
  assign(output,'gift1.out');rewrite(output);
  readln(n);
  for i:=1 to n do
    readln(c[i]);
  while not eof do
    begin
      readln(s);
      readln(money,sh);
      if (money<>0) and (sh<>0) then
        begin
          dec(account[find(s)],money);
          inc(account[find(s)],money mod sh);
          for i:=1 to sh do
            begin
              readln(s);
              inc(account[find(s)],money div sh);
            end;
        end
        else begin
          for i:=1 to sh do
            readln;
        end;
    end;
  for i:=1 to n do
    writeln(c[i],' ',account[i]);
  close(input);close(output);
end.

 

 posted on 2012-12-08 20:45  Sky-Grey  阅读(197)  评论(0编辑  收藏  举报