zoukankan      html  css  js  c++  java
  • 1055. The World's Richest (25)

    距离PAT考试还有14天最重要的是做透每一题

    (1)思路

    排序 怎么排都可以,反正不要用cin做数据输入

    充分认识到了cin的慢

    #include <cstdio>
    #include <string>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    struct re{
      char name[10];
      int age;
      int worth;
    
      re() {
        memset(name,0,sizeof(name));
        age=0;
        worth=0;
      }
    };
    
    int n,k;
    
    bool cmp(re r1,re r2) {
      if(r1.worth > r2.worth) {
        return true;
      } else if(r1.worth == r2.worth) {
        if(r1.age < r2.age) {
          return true;
        } else if(r1.age == r2.age) {
          if(strcmp(r1.name,r2.name) < 0) return true;
          else return false;
        }
      }
      return false;
    }
    
    int main() {
      scanf("%d %d",&n,&k);
      
      vector<re> data;
      data.resize(n);
      for(int i=0;i<n;i++) {
        scanf("%s %d %d",data[i].name,&(data[i].age),&(data[i].worth));
      }
      sort(data.begin(),data.end(),cmp);
      vector<int> book(201);
      fill(book.begin(),book.end(),0);
      vector<re> minidata;
      for(int j=0;j<n;j++) {
        if(book[data[j].age] < 100) {
          minidata.push_back(data[j]);
          book[data[j].age]++;
        }
      }
      for(int i=0;i<k;i++) {
        int num,amin,amax;
        scanf("%d %d %d",&num,&amin,&amax);
        vector<re> aged_data;
        for(int j=0;j<minidata.size();j++) {
          if(minidata[j].age<=amax && minidata[j].age>=amin) {
        aged_data.push_back(minidata[j]);
          }
        }
        //aged
        printf("Case #%d:
    ",i+1);
        if(aged_data.size() == 0) {
          printf("None
    ");
          continue;
        }
        int datasize=aged_data.size();
        num=min(datasize,num);
        for(int j=0;j<num;j++) {
          printf("%s",aged_data[j].name);
          printf(" %d %d
    ",aged_data[j].age,aged_data[j].worth);
        }
      }
      return 0;
    }

     

     下面是用cin的

    .......

  • 相关阅读:
    装饰设计模式
    Enum的基本使用
    java根据文件流判断文件类型(后缀名)
    Java正则表达式的用法
    java遍历Map
    java操作json
    struts2+ajax+jquery
    Hibernate注解
    oracle经典建表语句--scott建表
    Struts2 ui标签
  • 原文地址:https://www.cnblogs.com/tclan126/p/8570615.html
Copyright © 2011-2022 走看看