第一题:map搞搞

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

char s[100005];
map<char,int> m;

int main()
{
    while(gets(s))
    {
        int cnt = -1;
        int pos = 100000005;
        char ans;
        m.clear();
        int len = strlen(s);
        for(int i = 0; i < len; ++i)
        {
            if(s[i] >= 'a' && s[i] <= 'z')
            {
                s[i] = s[i] - 32;
            }
            if(s[i] >='A' && s[i] <= 'Z')
            {
                m[s[i]]++;
            }
            if(m[s[i]] >= cnt)
            {
                cnt = m[s[i]];
                ans = s[i];
                //pos = i;
            }
        }
        for(int i = 0; i < len; ++i)
        {
            if(m[s[i]] == cnt)
            {
                ans = s[i];
                break;
            }
        }
        cout<<ans<<cnt<<endl;

    }
    return 0;
}

第二题 哈弗曼树:DFS+优先队列模拟
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <cstring>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
const int maxn = 1e5;
vector<int> num[300];
struct Node{
    Node *left;
    Node *right;
    int id;
    int code;
    int num;
    friend bool operator < (const Node &a ,const Node &b){
        return a.num > b.num;
    }
}a[maxn];
priority_queue< Node > q;
string Code[300];
void dfs(Node *root,string now){
   if (root->left == NULL  && root->right == NULL){
        Code[root->code] = now;
        return;
   }
   string Now = now;
   if (root->left != NULL) dfs(root->left,Now + "0");
   if (root->right != NULL) dfs(root->right,Now + "1");
}
int main(){
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size(); i++){
        num[s[i]].push_back(i);
    }
    int cnt = 0;
    while (!q.empty()) q.pop();
    for (int i = 0; i < 300; i++){
        if ((int)num[i].size() > 0){
            a[cnt].code = i;
            a[cnt].id = cnt;
            a[cnt].num = (int)num[i].size();
            a[cnt].left = NULL;
            a[cnt].right = NULL;
            q.push(a[cnt]);
            cnt++;
        }
    }
    while (q.size() > 1){
        Node fr1 = q.top();
        q.pop();
        Node fr2 = q.top();
        q.pop();
        a[cnt].left = &a[fr1.id];
        a[cnt].right = &a[fr2.id];
        a[cnt].id = cnt;
        a[cnt].num = fr1.num + fr2.num;
        q.push(a[cnt]);
        cnt++;
    }
    Node f = q.top();
    q.pop();
    Node *Root = &f;
    dfs(Root,"");
    for (int i = 0; i < (int) s.size(); i++){
        cout << Code[s[i]];
    }
    cout << endl;
}
第三题:题意不清的模拟题,过不去,过了40% 请AC的大佬指正还需要注意那些细节,谢谢!
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

int main() {     int n, x;     scanf("%d", &n);     bool head = true, flag = true;     int pre = 0;     std::vector< int > ans;     while(flag && n--) {         scanf("%x", &x);         if(!x) {             if(!n) {                 flag = false;                 break;             }             scanf("%x", &x);             --n;             if(x > 15) flag = false;             else if(head) {                 pre = x;                 head = false;             } else if((pre + 1) % 16 != x) flag = false;             else pre = x;             if(!n) {                 flag = false;                 break;             }             scanf("%x", &x);             --n;             int t = x >> 4, len = x & 15;             std::vector< int > d;             if(len > n) {                 flag = false;                 break;             }             while(len--) {                 scanf("%x", &x);                 d.push_back(x);                 --n;             }             if(t == 1 || t == 2) std::sort(d.begin(), d.end());             if(t == 2) ans.insert(ans.end(), d.begin(), d.end());             else ans.insert(ans.end(), d.rbegin(), d.rend());         }     }     if(flag) {         for(int i = 0; i < ans.size(); ++i) {             if(i) printf(" ");             printf("0x%x", ans[i]);         }         puts("");     } else puts("FALSE");     return 0;
}