HOJ1263 水果
来源:互联网 发布:中年男士香水推荐知乎 编辑:程序博客网 时间:2024/06/10 04:25
一道很简单的题目,太浮躁了。WA了很多次。
http://acm.hdu.edu.cn/showproblem.php?pid=1263
主要是用qsort和对结构体的处理不熟悉导致.
最后想了个比较2的办法 代码东改西改 很烂了。
#include<stdio.h>#include<stdlib.h>#include<string.h>struct fruit{char name[100];char place[100];int n;};int cmp(const void *a,const void *b);main(){int N,M,m,i,j; struct fruit fit[101];scanf("%d",&N);while(N--){scanf("%d",&M);for(m=0;m<M;m++){scanf("%s %s %d",fit[m].name,fit[m].place,&fit[m].n);}for(m=0;m<M;m++){for(i=m+1;i<M;i++){if((strcmp(fit[m].place,fit[i].place)==0)&&(strcmp(fit[m].name,fit[i].name)==0)&&fit[i].n>0&&fit[m].n>0){fit[m].n+=fit[i].n; fit[i].n=-1; strcpy(fit[i].name,"\0"); strcpy(fit[i].place,"\0");}}}qsort(fit,M,sizeof(fit[0]),cmp);for(i=0;i<M;i++){if(fit[i].n<0)continue;if(i==0)printf("%s\n",fit[i].place); else { if((strcmp(fit[i].place,fit[i-1].place)!=0)) printf("%s\n",fit[i].place); }printf(" |----%s(%d)\n",fit[i].name,fit[i].n);}if(N!=0)printf("\n");}}int cmp(const void *a,const void *b){if(strcmp((*(struct fruit *)a).place,(*(struct fruit *)b).place)>0) return 1;if(strcmp((*(struct fruit *)a).place,(*(struct fruit *)b).place)==0){ if(strcmp((*( struct fruit *)a).name,(*(struct fruit *)b).name)>=0) return 1; else return -1;} elsereturn -1;}
- HOJ1263 水果
- 水果
- 水果
- 水果
- 水果
- 水果
- 水果
- 水果
- 水果水果我爱你。。
- 水果单词
- 上水果
- 水果保健
- 1040水果
- 水果表达方式
- 水果疗效
- 水果哥
- HDU1263:水果
- 葡萄(水果)
- 判断一个数是否能被17或35整除
- 理解form的get和post(转载)
- 十六周任务2:成绩排序
- vs2010发布、打包安装程序(超全超详细)
- 使用SetTimer要注意时间间隔的选取
- HOJ1263 水果
- URLRewrite伪静态与AspNetPager分页控件的结合
- 移植google操作系统android的5个步骤之(一)
- Ogre着色方式和光照模型(shading mode vs lighting model)
- 查找程序问题之道
- SQL数据库安全审计工具-xSQL Scanner1.6
- 安装Excel Server时报错“无法打开备份设备”
- MIPS-LINUX-中断处理
- 好文摘