1 条题解
-
0
C++ :
#include <stdio.h> #include <string.h> int main() { int n; while(scanf("%d",&n)!=EOF){ char name1[10][14];/*=(char **)malloc(sizeof(char));*/ char name2[10][14];/*=(char **)malloc(sizeof(char));*/ getchar(); for(int i=0;i<n;i++) { scanf("%s",name1[i]); getchar(); } int money[10]; int people[10]; int getmoney[10]={0}; for(int i=0;i<n;i++){ scanf("%s",name2[i]); getchar(); scanf("%d%d",&money[i],&people[i]); getchar(); /*if(money[i]==0||people[i]==0) continue;*/ int s=0; for( s=0;s<n;s++){/*给每个送出礼物的人减去他们所送出的钱*/ if(strcmp(name2[i],name1[s])==0){ getmoney[s]-=money[i]; break;} } for(int j=0;j<people[i];j++){ char str[10][14];/*不能用一维数组,必须要用二维的,否则就不能输入*/ scanf("%s",str[j]); getchar(); if(money[i]!=0&&people[i]!=0){ for(int r=0;r<n;r++){ if(strcmp(str[j],name1[r])==0){ getmoney[r]+=money[i]/people[i]; break; } } } } if(money[i]!=0&&people[i]!=0) getmoney[s]+=money[i]%people[i];/*如果分配不均匀的话,剩余归自己*/ } for(int w=0;w<n;w++){ for(int v=0;v<strlen(name1[w]);v++) printf("%c",name1[w][v]); printf(" "); printf("%d",getmoney[w]); printf("\n"); } } return 0; }
- 1
信息
- ID
- 1255
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者