zoukankan      html  css  js  c++  java
  • ccf集合竞价

    我不懂为什么是错误。然后零分。贴出测试。

    然后即使注释掉while循环中的break部分,也是如此。

      1 #include<iostream>
      2 #include<iomanip>
      3 using namespace std;
      4 typedef struct p
      5 {
      6     string str;
      7     float price;
      8     long long num;
      9 };
     10 typedef struct ans
     11 {
     12     float p;
     13     long long num;
     14 };
     15 p x[6000],x1[6000],x2[6000];
     16 ans an[6000];
     17 int main()
     18 {
     19     int i=0,j=0,k=0,l=0;
     20     while(cin>>x[i].str)//读入数据
     21     {
     22         if(x[i].str=="cancel")
     23         {
     24             int no;
     25             cin>>no;
     26             no--;
     27             x[no].str="cancel";
     28             x[no].price=0;
     29             x[no].num=0;
     30         }
     31         else if(x[i].str=="buy"||x[i].str=="sell")
     32         {
     33             float p;
     34             long long n;
     35             cin>>p;
     36             cin>>n;
     37             x[i].price=p;
     38             x[i].num=n;
     39             i++;
     40         }
     41         else
     42             break;
     43     }
     44     for(j=0;j<i;j++)//数据分类
     45     {
     46         if(x[j].str=="buy")
     47         {
     48             x1[k].str=x[j].str;
     49             x1[k].price=x[j].price;
     50             x1[k].num=x[j].num;
     51             k++;
     52         }
     53         if(x[j].str=="sell")
     54         {
     55             x2[l].str=x[j].str;
     56             x2[l].price=x[j].price;
     57             x2[l].num=x[j].num;
     58             l++;
     59         }
     60     }
     61     
     62     int s=0,t=0;
     63     for(s=0;s<k;s++)//数据排序
     64     {
     65         for(t=s;t<k;t++)
     66         {
     67             if(x1[t].price>x1[s].price)
     68             {
     69                 swap(x1[t],x1[s]);
     70             }
     71         }
     72     } 
     73      
     74     for(s=0;s<l;s++)
     75     {
     76         for(t=s;t<l;t++)
     77         {
     78             if(x2[t].price<x2[s].price)
     79             {
     80                 swap(x2[t],x2[s]);
     81             }
     82         }
     83     }
     84     
     85     int r0=0,r1=0,r2=0;
     86     
     87     for(s=0;s<l;s++)
     88     {
     89          r0=x2[s].price;
     90          an[s].p=x2[s].price;
     91          r1=0;
     92          r2=0;
     93          for(t=0;t<k;t++)
     94          {
     95              if(x1[t].price>=x2[s].price)//买得起
     96             {
     97                 r1=r1+x1[t].num;
     98                 r2=r2+x2[s].num;
     99             }
    100         }
    101         if(r1>r2)
    102         {
    103             an[s].num=r2;
    104         }
    105         else
    106         {
    107             an[s].num=r1;
    108         }
    109         
    110     }
    111     for(s=0;s<l;s++)//找到最大的价格
    112     {
    113         for(t=s;t<l;t++)
    114         {
    115             if(an[t].p>an[s].p)
    116             {
    117                 swap(an[t],an[s]);
    118             }
    119         }
    120     }
    121     cout<<setiosflags(ios::fixed)<<setprecision(2)<<an[0].p;
    122     cout<<" "<<an[0].num<<endl; 
    123     return 0;
    124 }
  • 相关阅读:
    django 如何重用app
    vim常用命令
    linux find grep
    linux su su-的区别
    linux定时任务crontab
    linux shell的单行多行注释
    python字符串的截取,查找
    gdb调试
    python字符转化
    python读写文件
  • 原文地址:https://www.cnblogs.com/zhenzhenhuang/p/6188290.html
Copyright © 2011-2022 走看看