C 写的,WA 求指点

#include <stdio.h>
#include <strings.h>

struct person
{
char name[15];
int orig_money;
int recv_money;
};

int main()
{
int num, i = 0, j = 0, k = 0, orig_money = 0, ntmp = 0, each_money = 0;
char ctmp[15];

scanf(" %d", &num);

struct person p[num];

for (; i < num; i++)
{
scanf(" %s", p[i].name);
p[i].orig_money = 0;
p[i].recv_money = 0;
}

for (i = 0; i < num; i++)
{
scanf(" %s %d %d", ctmp, &orig_money, &ntmp);

for(k = 0; k < num; k++)
if (strcmp(ctmp, p[k].name) == 0)
{
p[k].orig_money = orig_money;
break;
}

if (ntmp == 0) continue;

each_money = orig_money / ntmp;
p[i].recv_money += (orig_money - ntmp * each_money);

for(j = 0; j < ntmp; j++)
{
memset(ctmp, 0, sizeof(ctmp));

scanf(" %s", ctmp);

for(k = 0; k < num; k++)
if (strcmp(ctmp, p[k].name) == 0)
{
p[k].recv_money += each_money;
break;
}
}
}

for (i = 0; i < num; i++)
printf("%s %d\n", p[i].name, p[i].recv_money - p[i].orig_money);

return 0;
}

2 条评论

  • @ 2014-05-10 18:48:02

    AC哦!

  • @ 2014-05-10 18:47:41

    pascal:
    var

    np,r :byte;

    name1,name2:string;

    name :array[1..10] of string;

    m :array[1..10] of longint;

    i,j,k,q :longint;

    begin

    readln(np);

    for i:=1 to np do

    readln(name[i]);

    for i:=1 to np do

    begin

    readln(name1);

    readln(q,r);

    if r<>0 then

    begin

    for j:=1 to np do

    if name[j]=name1 then m[j]:=m[j]+(q mod r)-q;

    q:=q-(q mod r);

    for j:=1 to r do

    begin

    readln(name2);

    for k:=1 to np do

    if name[k]=name2 then m[k]:=m[k]+q div r;

    end;

    end;

    end;

    for i:=1 to np do

    writeln(name[i],' ',m[i]);

    end.

  • 1

信息

ID
1035
难度
2
分类
模拟 点击显示
标签
(无)
递交数
5222
已通过
2901
通过率
56%
被复制
19
上传者