【1153】Decode Registration Card of PAT (25分)

简介: 【1153】Decode Registration Card of PAT (25分)【1153】Decode Registration Card of PAT (25分)
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<string>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue> 
#include<unordered_map>
using namespace std;  
把map的key&value存到vector中,用sort对vector排序
注意c_str()可使printf用%s输出string类型字符串,为一指针
//编号规则,第1位代表pat等级,第2-4位为考场编号
//第5-10位为测试日期,第11-13位为测试者编号
struct node{
  string t;
  int value;
};
bool cmp(const node &a, const node &b){
  return a.value !=b.value ? a.value >b.value : a.t<b.t;
  //成绩不等则按成绩降序,成绩相等则按编号"升序"
}
int main(){   
  int n,k,num;
  string s;
  cin>>n>>k; //n个学生的数据,k次查询操作
  vector<node>v(n); //n个vector存储学生信息
  for(int i=0;i<n;i++){
    cin>>v[i].t>>v[i].value;//t存储对应学生编号,value存pat分数
  }
  for(int i=1;i<=k;i++){
    cin >>num>>s;//num为操作功能项,s为操作的字符
    printf("Case %d: %d %s\n",i,num,s.c_str());
    //输出第i个case:功能项,输入的字符串
    vector<node> ans;
    int cnt=0,sum=0;
    if(num==1){ 
      //第1个功能:输入考试等级,找出该等级的考生,按照成绩降序,准考证升序排序
      //按照等级查询,枚举匹配的学生然后排序
      for(int j=0;j<n;j++)
        if(v[j].t[0]==s[0]) 
          ans.push_back(v[j]);
    }else if(num==2){ 
      //第2个功能:输入考场号,统计该考场的考生数和总得分
      //按照考场查询,枚举匹配学生然后计数求和
      for(int j=0;j<n;j++){
        if(v[j].t.substr(1,3) == s){//截取出考场编号判断
          cnt++;
          sum += v[j].value;
        }
      }
      if(cnt!=0)  printf("%d %d\n",cnt,sum);
      //打印出改考场的  考生数 总分
    }else if(num==3) {
        //第3个功能:输入考试日期,查询该日期下所有考场的人数,按照人数降序,考场号升序
        //按日期查询每个考场人数,用unordered_map存储,再排序汇总
      unordered_map<string,int> m;
      for(int j=0;j<n;j++)
        if(v[j].t.substr(4,6)==s)  //找符合日期的考场
          m[v[j].t.substr(1,3)]++;//考场编号对应数加1
      for(auto it:m) {
        node t;//这里写得和柳神代码不同,可能是编译器用2012VS太老的原因之前那个会报出
        t.t=it.first;
        t.value=it.second;
        ans.push_back(t);
      }
    }
    //把map的key&value存到vector中,用sort对vector排序
    //m是map,ans是vector
    sort(ans.begin(),ans.end(),cmp); //排序
    for(int j=0;j<ans.size();j++)
      printf("%s %d\n",ans[j].t.c_str(),ans[j].value);
        //输出考场编号和总人数
    if ( (  (num==1 || num==3)&&ans.size()==0 )|| (num==2&&cnt==0) )
      printf("NA\n");
  }
  system("pause");
  return 0;
}
相关文章
|
23天前
|
JSON JavaScript API
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 错误分析
本文探讨了Python中处理JSON数据时遇到的`JSONDecodeError`,该错误通常由JSON格式错误或数据源问题引起。解决方法包括检查数据源、使用异常处理机制和调试日志记录。示例代码展示了如何从文件和API读取JSON并处理异常。注意事项涉及验证JSON规范、处理特殊字符和选择合适解析器。通过这些步骤,可以有效解决JSON解码错误,确保数据正确解析。
26 0
|
10月前
UE [ DT Url ] Url Encode Decode Plugin description
UE [ DT Url ] Url Encode Decode Plugin description
49 0
|
前端开发 JavaScript
前端vue:解决Invalid prop: type check failed for prop “model“. Expected Object, got Array问题
前端vue:解决Invalid prop: type check failed for prop “model“. Expected Object, got Array问题
1188 0
前端vue:解决Invalid prop: type check failed for prop “model“. Expected Object, got Array问题
|
11月前
|
存储 C++ Windows
【PAT甲级 - C++题解】1153 Decode Registration Card of PAT
【PAT甲级 - C++题解】1153 Decode Registration Card of PAT
73 0
cdo 合并nc文件时,报错:Error(cdf_put_vara_double):NetCDF:Numeric conversion not representable
cdo 合并nc文件时,报错:Error(cdf_put_vara_double):NetCDF:Numeric conversion not representable
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
106 0
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
The Soft Link between IM Level Storage Location and WM level Storage Type?(1)
The Soft Link between IM Level Storage Location and WM level Storage Type?(1)
The Soft Link between IM Level Storage Location and WM level Storage Type?(1)
The Soft Link between IM Level Storage Location and WM level Storage Type?(2)
The Soft Link between IM Level Storage Location and WM level Storage Type?(2)
The Soft Link between IM Level Storage Location and WM level Storage Type?(2)
SAP WM Storage Type Search配置里的Storage Class & WPC标记
SAP WM Storage Type Search配置里的Storage Class & WPC标记
SAP WM Storage Type Search配置里的Storage Class & WPC标记
Cannot Load KPI tile with Error message - Missing parameterization request
Cannot Load KPI tile with Error message - Missing parameterization request
95 0
Cannot Load KPI tile with Error message - Missing parameterization request