关注
第一题: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;
}
查看原帖
点赞 评论
相关推荐

点赞 评论 收藏
分享

点赞 评论 收藏
分享
牛客热帖
更多
- 1... 面试最后的反问环节,能问些什么?(附特供问题)2.6W
- 2... BG一般,如何逆天改命拿下后端秋招SSP?1.5W
- 3... 从面试官的角度看待一场面试是怎么样的?7408
- 4... 害,找工作哪有不上当的!5291
- 5... 团、节、东孝子全部启动启动启动!(26届后端秋招总结)5050
- 6... 作为普通家庭出身的我,为什么非大厂不可?4997
- 7... 双非硕的十月份秋招总结4432
- 8... 感觉每个人都有自己的苦恼4217
- 9... 项目经历混乱?STAR法则手把手教你梳理(附真实案例分析过程)3704
- 10... 一眼望到头的生活VS望不到头的生活3472
正在热议
更多
# 实习在多还是在精 #
24107次浏览 189人参与
# 你的房租占工资的比例是多少? #
61306次浏览 742人参与
# 未岚大陆求职进展汇总 #
3150次浏览 48人参与
# 秋招踩过的“雷”,希望你别再踩 #
57705次浏览 833人参与
# 我的求职进度条 #
37962次浏览 582人参与
# 大厂VS公务员你怎么选 #
13663次浏览 216人参与
# 爱玛科技集团求职进展汇总 #
34608次浏览 231人参与
# 如果不考虑收入,你最想做什么工作? #
31101次浏览 180人参与
# 柠檬微趣工作体验 #
13207次浏览 72人参与
# 机械人的保底公司是哪一家? #
40623次浏览 133人参与
# 顺丰求职进展汇总 #
61961次浏览 306人参与
# 华为池子有多大 #
102145次浏览 732人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
135422次浏览 868人参与
# 如果再来一次,你还会学硬件吗 #
137849次浏览 1441人参与
# 如何用一句话描述你的职业 #
24897次浏览 172人参与
# 高学历就一定能找到好工作吗? #
55496次浏览 607人参与
# 如何排解工作中的焦虑 #
219611次浏览 2104人参与
# 实习下班不想学习,正常吗? #
13749次浏览 150人参与
# 反问环节如何提问 #
112422次浏览 2349人参与
# 你见过哪些工贼行为 #
11482次浏览 76人参与
# 工作中,努力重要还是选择重要? #
204472次浏览 2074人参与
# 校招谈薪一定要知道的事 #
9596次浏览 92人参与