【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;
}
相关文章
|
10月前
|
移动开发 JavaScript HTML5
el-input限制输入整数等分析
本文介绍了在Vue中限制el-input只能输入整数的几种方式,包括设置type为number,使用inputmode属性,自定义指令,计算属性,使用onafterpaste和onkeyup事件以及使用el-input-number的precision属性。每种方式都有其优缺点,可以根据实际需求选择合适的方式。比较建议用自定义指令的方式来实现。
1574 0
el-input限制输入整数等分析
|
存储 C++ Windows
【PAT甲级 - C++题解】1153 Decode Registration Card of PAT
【PAT甲级 - C++题解】1153 Decode Registration Card of PAT
100 0
|
编解码
解码错误。‘gb2312‘ codec can‘t decode byte 0xf3 in position 307307: illegal multibyte sequence
解码错误。‘gb2312‘ codec can‘t decode byte 0xf3 in position 307307: illegal multibyte sequence
213 0
|
Python
【hacker的错误集】TypeError: can‘t multiply sequence by non-int of type ‘str‘
我比较喜欢通过单词的意思来分析报错 TypeError类型错误 multiply乘 sequence 序列 通过分析可以得出报错意思大概是类型错误:无法将序列与字符串类型的非整数相乘
433 0
【hacker的错误集】TypeError: can‘t multiply sequence by non-int of type ‘str‘
|
存储 缓存 应用服务中间件
解决问题:net::ERR_CONTENT_LENGTH_MISMATCH 206 (Partial Content)
问题 今天遇到一个问题,Web 播放器在播放对象存储服务中的某个视频文件时,总是不断的报错 206(Partial Content),具体的信息如下: net::ERR_CONTENT_LENGTH_MISMATCH 206 (Partial Content) 造成的结果就是视频播放失败。 播放器报错截图如下:
1690 0
解决问题:net::ERR_CONTENT_LENGTH_MISMATCH 206 (Partial Content)
base -2 Number——进制转换
题目描述 Given an integer N, find the base −2 representation of N. Here, S is the base −2 representation of N when the following are all satisfied: S is a string consisting of 0 and 1. Unless S= 0, the initial character of S is 1. Let S=SkSk−1…S0, then S0×(−2)0+S1×(−2)1+…+Sk×(−2)k=N.
132 0
【1048】Find Coins (25 分)
【1048】Find Coins (25 分) 【1048】Find Coins (25 分)
136 0
|
Web App开发 算法
名词小结:base href、GreaseMonkey、Varchar、char、网速的计算
base href、GreaseMonkey、Varchar、char、网速的计算
1226 0