PAT(Decode Registration Card of PAT)


  1. 存在ans数组中再打印就没问题,直接判断打印就要凉(我也不是很懂里面的原因)
  2. 注意unordered_map与map之间的区别
  3. auto是个好东西,可以不用iterator了。

正确代码:

#include
#include
#include
#include
#include 
#include
#include
using namespace std;
class card{
    public:
    string s;
    int t;
};
bool cmp(card&a,card&b){
    if(a.t==b.t){
        return a.sb.t;
    }
}
int main(){
    int i,j,a,b;
    cin>>a>>b;
    string s;
    int score;
    vectorv;
    for(i=0;i>s>>score;
        card c;
        c.s=s;
        c.t=score;
        v.push_back(c);
    }
    int type;
    string input;
    for(j=1;j<=b;j++){
        vectorans;
        cin>>type>>input;
        printf("Case %d: %d %s\n", j, type, input.c_str());
        int count=0,sum=0;
        if(type==1){
            for(i=0;im;
            for(i=0;i

错误代码:

#include
#include
#include
#include
#include
#include
#include 
using namespace std;
class card{
    public:
    string raw;
    int grade;
    void set(string input,int score){
        raw=input;
        grade=score;
    }
};
bool cmp1(card &a,card &b){
    if(a.grade!=b.grade)
    {
        return a.grade>b.grade;
    }
    else{
        // site,time,id
        // cout<m;
struct Node{
    string site;
    int times;
};
bool cmp3(Node &a,Node &b){
    if(a.times!=b.times){
        return a.times>b.times;        
    } 
    else{
        return a.sitec;
    scanf("%d %d\n",&a,&b);
    //cin>>a>>b;
    int i,j;
    card temp;    
    for(i=0;i>s;
        cin>>score;
        temp.set(s,score);
        c.push_back(temp);
    }
    int type;
    char cc;
    string site;    
    string time;
    for(j=0;j>type;
        if(type==1){
            // case 1
            cin>>cc;
            sort(c.begin(),c.end(),cmp1);
            bool is=false;
            printf("Case %d: %d %c\n",j+1,type,cc);
            // cout<<"Case "<>site;
            int sum=0;
            int count=0;
            for(i=0;i>time;
            for(i=0;iv;
            for(auto it: m){
                Node node;
                node.site=it.first;
                node.times=it.second;
                v.push_back(node);
            }           
            printf("Case %d: %d %s\n",j+1,type,time.c_str()); 
            // cout<<"Case "<

你可能感兴趣的:(PAT(Decode Registration Card of PAT))