PAT-1153(Decode Registration Card of PAT)+unordered_map的使用+vector的使用+sort条件排序的使用
Decode Registration Card of PAT
PAT-1153
- 这里需要注意题目的规模,并不需要一开始就存储好所有的满足题意的信息
- 这里必须使用unordered_map否则会超时
- vector的使用需要注意,只有一开始赋予了容量才能读取。
- 不需要使用set也可以
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<set>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=10004;
int n,m;
struct Node{
string code;
char type;
int site;
string date;
int number;
int score;
Node(){
}
Node(string co,char ty,int si,string da,int nu,int sc):
code(co),type(ty),site(si),date(da),number(nu),score(sc){
}
bool operator<(const Node& node)const{
if(score==node.score){
return code<node.code;
}else return score>node.score;
}
int times;
};
struct NType3{
int site,times;
NType3(){
}
NType3(int a,int b):site(a),times(b){
}
bool operator<(const NType3& node2)const{
if(times==node2.times){
return site<node2.site;
}else return times>node2.times;
}
};
set<Node>type1[26];
map<int,int>sit;
map<int,int>totscore;
map<int,int>dat[1000006];
set<NType3>type3[1000006];
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
string code;int score;
cin>>code>>score;
char level=code[0];
int site=stoi(code.substr(1,3));
string date=code.substr(4,6);
int number=stoi(code.substr(10));
// cout<<level<<" "<<site<<" "<<date<<" "<<number<<endl;
Node node=Node(code,level,site,date,number,score);
sit[site]++;
totscore[site]+=score;
type1[level-'A'].insert(node);
if(dat[stoi(date)][site]==0){
set<NType3>te;
te.insert(NType3(site,0));
type3[stoi(date)].insert(NType3(site,0));
}
dat[stoi(date)][site]++;
}
for(int i=0;i<m;i++){
int type;string s;
cin>>type>>s;
if(type==1){//level
set<Node> now=type1[s[0]-'A'];
set<Node>::iterator it;
int num=0;
for(it=now.begin();it!=now.end();it++){
Node no=*it;
cout<<no.code<<" "<<no.score<<endl;
num++;
}
if(num==0)
cout<<"NA"<<endl;
}else if(type==2){//site
int numsit=sit[stoi(s)];
if(numsit==0){
cout<<"NA"<<endl;
}else cout<<sit[stoi(s)]<<" "<<totscore[stoi(s)]<<endl;
}else{//date
set<NType3> now=type3[stoi(s)];
set<NType3> temp;
for(set<NType3>::iterator it=now.begin();it!=now.end();it++){
NType3 no=*it;
int site=no.site;
int times=dat[stoi(s)][site];
no.times=times;
temp.insert(no);
}
set<NType3>::iterator it;
int num=0;
for(it=temp.begin();it!=temp.end();it++){
NType3 no=*it;
cout<<no.site<<" "<<no.times<<endl;
num++;
}
if(num==0)
cout<<"NA"<<endl;
}
}
return 0;
}
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<set>
#include<map>
#include<cmath>
#include<vector>
#include<unordered_map>
using namespace std;
const int maxn=10004;
int n,m;
struct Node{
string code;
int value;
};
bool cmp(Node& node1,Node& node2){
if(node1.value==node2.value){
return node1.code<node2.code;
}else return node1.value>node2.value;
}
int main(){
cin>>n>>m;
vector<Node>v(n);//只有指定了容器大小才能使用下面输入语句
for(int i=0;i<n;i++){
string code;int score;
// cin>>code>>score;
// Node node;
// node.code=code;
// node.value=score;
// v.push_back(node);
cin>>v[i].code>>v[i].value;
}
for(int i=1;i<=m;i++){
int type;string s;
cin>>type>>s;
printf("Case %d: %d %s\n",i,type,s.c_str());
// cout<<"Case "<<i<<": "<<type<<" "<<s<<endl;
if(type==1){
vector<Node>ve;
for(Node item:v){
if(item.code.substr(0,1)==s){
ve.push_back(item);
}
}
if(ve.size()==0)
printf("NA\n");
else{
sort(ve.begin(),ve.end(),cmp);
for(Node item:ve){
printf("%s %d\n",item.code.c_str(),item.value);
// cout<<item.code<<" "<<item.value<<endl;
}
}
}else if(type==2){
int num=0,tot=0;
for(Node item:v){
if(s==item.code.substr(1,3)){
num++;
tot+=item.value;
}
}
if(num==0)
printf("NA\n");
else {
printf("%d %d\n",num,tot);
// cout<<num<<" "<<tot<<endl;
}
}else if(type==3){
unordered_map<string,int>ma;
for(Node item:v){
if(s==item.code.substr(4,6)){
string site=item.code.substr(1,3);
ma[site]++;
}
}
if(ma.size()==0)
printf("NA\n");
else{
vector<Node>now;
for(auto item:ma){
now.push_back({item.first,item.second});
}
sort(now.begin(),now.end(),cmp);
for(Node item:now){
printf("%s %d\n",item.code.c_str(),item.value);
}
}
}
}
// cout<<"jhjj"<<endl;
return 0;
}
PAT-1153(Decode Registration Card of PAT)+unordered_map的使用+vector的使用+sort条件排序的使用的更多相关文章
- PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)
1095 解码PAT准考证/1153 Decode Registration Card of PAT(25 分) PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级: ...
- PAT Advanced 1153 Decode Registration Card of PAT (25 分)
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- PAT甲级——1153.Decode Registration Card of PAT(25分)
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- 1153 Decode Registration Card of PAT (25 分)
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- 1153 Decode Registration Card of PAT
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- PAT A1153 Decode Registration Card of PAT (25 分)——多种情况排序
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- PAT_A1153#Decode Registration Card of PAT
Source: PAT A1153 Decode Registration Card of PAT (25 分) Description: A registration card number of ...
- 1093. Count PAT’s (25)-统计字符串中PAT出现的个数
如题,统计PAT出现的个数,注意PAT不一定要相邻,看题目给的例子就知道了. num1代表目前为止P出现的个数,num12代表目前为止PA出现的个数,num123代表目前为止PAT出现的个数. 遇到P ...
- PAT 乙级 1040.有几个PAT C++/Java
题目来源 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位( ...
随机推荐
- How many integers can you find HDU - 1796 容斥原理
题意: 给你一个数n,找出来区间[1,n]内有多少书和n不互质 题解: 容斥原理 这一道题就让我真正了解容斥原理的实体部分 "容斥原理+枚举状态,碰到奇数加上(n-1)/lcm(a,b,c. ...
- java——继承、抽象方法
基本上大量篇章都是为了解决重名造成的各种问题,如果所有名称都不会重名,那么其实不会有多大问题 父类与子类中的成员变量重名问题: 成员方法重名时如果调用方法: 继承中方法的覆盖重写: 继承中构造函数: ...
- 二叉树增删改查 && 程序实现
二叉排序树定义 一棵空树,或者是具有下列性质的二叉树:(1)若左子树不空,则左子树上所有结点的值均小于它的根结点的值:(2)若右子树不空,则右子树上所有结点的值均大于它的根结点的值:(3)左.右子树也 ...
- SpringBoot简单整合redis
Jedis和Lettuce Lettuce 和 Jedis 的定位都是Redis的client,所以他们当然可以直接连接redis server. Jedis在实现上是直接连接的redis serve ...
- 国产网络测试仪MiniSMB - 双击就可以直接编辑数据报文字段(如IP地址)
国产网络测试仪MiniSMB(www.minismb.com)是复刻smartbits的IP网络性能测试工具,是一款专门用于测试智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此以太 ...
- 交换机上禁止某个MAC地址通信
当分析出网络中某台机器中毒时而有不知道它的具体位置,我们可以通过获取其MAC地址然后在交换机上禁止其MAC来达到隔离它的效果.通过ARP表查询IP地址对应的MAC地址,再将该MAC地址加入黑名单过滤. ...
- Ubuntu下跑通py-faster-rcnn、详解demo运作流程
在不同的服务器不同的机器上做过很多次实验,分别遇到各种不一样的错误并且跑通Py-Faster-RCNN,因此,在这里做一个流程的汇总: 一.下载文件: 首先,文件的下载可以有两种途径: 1.需要在官网 ...
- 在利用手背扫描图像+K因子 对室内温度进行回归预测时碰到的问题
1. 关于多输入流: 由于本Mission是双输入, 导师要求尽量能使用Inception之诸, 于是输入便成了问题. 思考: 在Github上找到了keras-inceptionV4进行对网络头尾的 ...
- npm version ^ meaning
npm version ^ meaning ^ 更新版 https://docs.npmjs.com/cli/v6/commands/npm-version https://github.com/ge ...
- JavaScript var, let, const difference All In One
JavaScript var, let, const difference All In One js var, let, const 区别 All In One 是否存在 hoisting var ...