zoukankan      html  css  js  c++  java
  • (周六赛1)水果

    //题意(解):结构体排序+strcmp

    自己每次都要被一些问题给卡住,也不知道当时在想什么 so sadT ^ T

    战斗力-5的渣渣

    Input
    第一行正整数N(0<N<=10)表示有N组测试数据.
    每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(小写字母组成,长度不超过80),水果产地(小写字母组成,长度不超过80)和交易的水果数目(正整数,不超过100)组成.

    Output
    对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的产地,名称和销售数目的信息.水果先按产地分类,产地按字母顺序排列;同一产地的水果按照名称排序,名称按字母顺序排序.
    两组测试数据之间有一个空行.最后一组测试数据之后没有空行.

    Sample Input
    1
    5
    apple shandong 3
    pineapple guangdong 1
    sugarcane guangdong 1
    pineapple guangdong 3
    pineapple guangdong 1

    Sample Output
    guangdong
    |----pineapple(5)
    |----sugarcane(1)
    shandong
    |----apple(3)

    #include<stdio.h>
    
    #include<string.h>
    
    #include<algorithm>
    
    using namespace std;
    
    
    
    struct fruit
    
    {
    
    char name[1000];
    
    char place[1000];
    
    int  s;
    
    }stu[1000];
    
    
    
    bool cmp(fruit a,fruit b)
    
    {
    
    if(strcmp(a.place,b.place)!=0)
    
    return strcmp(a.place,b.place)<0;
    
    if(strcmp(a.place,b.place)==0&&strcmp(a.name,b.name)!=0)
    
    return strcmp(a.name,b.name)<0;
    
    }
    
    
    
    int main()
    
    {
    
    int n,m,i,j,k;
    
    int b[101],c[101],p[101];
    
    scanf("%d",&n);
    
    while(n--)
    
    {
    
    scanf("%d",&m);
    
    for(i=0;i<m;i++)
    
    scanf("%s %s %d",stu[i].name,stu[i].place,&stu[i].s);
    
    sort(stu,stu+m,cmp);
    
    memset(b,0,sizeof(b));
    
    memset(c,0,sizeof(c));
    
    memset(p,0,sizeof(p));
    
    for(i=0;i<m;i++)
    
    for(j=i+1;j<m;j++)
    
    {
    
    if(strcmp(stu[i].place,stu[j].place)==0&&c[i]!=1)
    
    c[j]=1;
    
    if(strcmp(stu[i].name,stu[j].name)==0&&strcmp(stu[i].place,stu[j].place)==0&&b[i]!=1)
    
    {
    
    p[i]+=stu[j].s;
    
    b[j]=1;
    
    }
    
    }
    
    b[0]=0;
    
    
    
    for(i=0;i<m;i++)
    
    {
    
    if(c[i]!=1)
    
    printf("%s
    ",stu[i].place);
    
    if(b[i]!=1)
    
    printf("   |----%s(%d)
    ",stu[i].name,p[i]+stu[i].s);
    
    }
    
    if(n)
    
    printf("
    ");
    
    }
    
    return 0;
    
    }
     
     
  • 相关阅读:
    self 和 super 关键字
    NSString类
    函数和对象方法的区别
    求两个数是否互质及最大公约数
    TJU Problem 1644 Reverse Text
    TJU Problem 2520 Quicksum
    TJU Problem 2101 Bullseye
    TJU Problem 2548 Celebrity jeopardy
    poj 2586 Y2K Accounting Bug
    poj 2109 Power of Cryptography
  • 原文地址:https://www.cnblogs.com/awsent/p/4266875.html
Copyright © 2011-2022 走看看