HDU oj 水果 题目1263
来源:互联网 发布:常用的推荐算法 编辑:程序博客网 时间:2024/05/17 01:05
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;struct app{ char name[81];//名称 char add[81];//地址 int num;//数量 }guo[100];int cmp(const void *a,const void *b){//按照要求结构体排序 struct app *c= (app *)a; struct app *d= (app *)b; if(strcmp(c->add,d->add)!=0) return strcmp(c->add,d->add); else return strcmp(c->name,d->name); }int main(){ int n,m; scanf("%d",&n); while(n--){ int j=0; scanf("%d\n",&m); for(int i=0;i<m;i++) scanf("%s %s %d",guo[i].name,guo[i].add,&guo[i].num); qsort(guo,m,sizeof(guo[0]),cmp); //sort(guo,guo+m,cmp); for(int i=1;i<m;i++) { if(strcmp(guo[i].add,guo[i-1].add)==0&&strcmp(guo[i].name,guo[i-1].name)==0)//add,name都相等相加 前边的变为0 {guo[i].num+=guo[i-1].num; guo[i-1].num=0; } } printf("%s\n",guo[j].add); for(j=0;j<m;j++) { if(j!=0&&strcmp(guo[j].add,guo[j-1].add)!=0) printf("%s\n",guo[j].add);//只要地址和前边的不同就是新地址 输出 if(guo[j].num!=0) printf(" |----%s(%d)\n",guo[j].name,guo[j].num);//输出数量不为0的水果的名字 } if(n) printf("\n"); //if(n!=0)竟然也会错 } return 0;}
0 0
- HDU oj 水果 题目1263
- 题目1107:搬水果 九度OJ
- 九度OJ题目1107:搬水果
- 九度OJ 题目1172:哈夫曼树&题目1107:搬水果
- hdu 1263 水果
- hdu - 1263 水果
- HDU 1263 水果
- hdu 1263 水果
- HDU 1263 水果
- 水果 hdu 1263 模拟
- HDU 1263 水果
- HDU 1263 水果
- hdu 1263 水果
- HDU 1263 水果
- hdu 1263 水果
- hdu 1263 水果
- hdu 1263 水果
- hdu 1263 水果
- UBUNTU 下编译安装opencv 2.3.1
- 多态在 Java 和 C++ 编程语言中的实现比较
- Linux cut 命令
- HDU 1237 简单计算器
- 无刷双馈轴带发电机
- HDU oj 水果 题目1263
- Axis2,反序列化抛出异常simpleDeserializer encountered a child element , which is not expected,in something it
- Android:AS环境下用AIDL进行IPC
- 6大设计原则(2):里氏替换原则
- hdu 2199 Can you solve this equation?
- loadrunner11提示loadrunner controller cannot create vusers?
- 黑马程序员----C语言函数
- 如何在mac下配置vim
- linux下python安装 nose lapack atlas numpy scipy sklearn