牛客网题库公司真题技术(软件)信息技术类 C++工程师 2021阅文C++方向笔试卷

以上的标题就是牛客网这个试卷的位置,链接在这里不确定以后是不是有效,我自己做个记录的:2021阅文C++方向笔试卷

2021年春招又加了很多试卷这个要往后翻几页了,这是我2020年底无聊做的,我就分享一下。(有的输入输出的循环题目字面没说循环几次而我给了for循环几次是因为是试错试出来的,这个循环大可不必限制次数)。我是主要是STL来解决的,有几个是C++语法题。

看题:

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <sstream>using namespace std;
class A{public:A(int x,int y):m_x(x),m_y(y){}bool operator==(A const& that)const{return m_x==that.m_x && m_y==that.m_y;}int m_x;int m_y;
};void printMax(vector<A> vs,int temp){vector<int> v;typedef vector<A>::iterator IT;typedef vector<int>::iterator I;for(IT it = vs.begin();it!=vs.end();++it){if((*it).m_y==temp)v.push_back((*it).m_x);}int tmp = 1;for(I i=v.begin();i!=v.end();++i){tmp = tmp>(*i)?tmp:(*i);}cout << tmp << endl;
}int main()
{typedef vector<A>::iterator  IT;string input;int temp = 1;getline(cin,input);stringstream stringin(input);int num;vector<A> vs;while(stringin >> num){if(vs.empty())vs.push_back(A(num,1));else{IT fit = find(vs.begin(),vs.end(),A(num,1));if(fit != vs.end()){if(temp<++(*fit).m_y){temp=(*fit).m_y;}}else{vs.push_back(A(num,1));}}}printMax(vs,temp);return 0;
}

#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
using namespace std;
class CMP{public:bool operator()(int const& a,int const& b){return a > b;}
};int main()
{vector<int> vs;typedef vector<int>::iterator IT;unsigned int temp=0;string input;cin >> temp;cin.ignore();getline(cin,input);stringstream stringin(input);int num = 0,max = 0;while (stringin >> num) {if(vs.empty()){vs.push_back(num);max = num;}else{vs.push_back(num);max= max>num?max:num;}}CMP cmp;sort(vs.begin(),vs.end(),cmp);IT it = vs.begin();for(int i =0;i<(int)temp;++i){++it;}cout << (*it) <<endl;return 0;
}

#include <iostream>
using namespace std;
class ScopedPtr {public:static ScopedPtr& getInstance(){return s_instance;}ScopedPtr(int* m_b=NULL):m_a(m_b){}private:int *m_a;friend int& operator*(ScopedPtr&);static ScopedPtr s_instance;//指针
};ScopedPtr ScopedPtr::s_instance;int&  operator *(ScopedPtr& d){return *(d.m_a);
}void test(int n) {ScopedPtr ptr(new int(n));*ptr *= 2;std::cout << *ptr << std::endl;
}int main () {int n = 0;std::cin >> n;test(n);return 0;
}

#include <iostream>
#include <bitset>
using namespace std;
class ITOB{public:ITOB(int num=0):m_num(num){}void itob(){if(m_num <= 0xff){char s_num  = (char)m_num;s_num = (s_num | 0x80);bitset<8> bs(s_num);cout <<  bs << endl;}else if((m_num >= 0xff) && (m_num <= 0xffff)){char s1 = (char)(m_num | 0x80);char s2 = (m_num >> 7 & 0xff) & 0x7F;bitset<8> bs1(s1);bitset<8> bs2(s2);cout <<  bs2 << bs1 << endl;}}int m_num;
};int main()
{ITOB ib;cin >> ib.m_num;ib.itob();return 0;
}

#include <iostream>
#include <vector>
#include <list>
#include <sstream>
#include <cstring>
using namespace std;
int main()
{string input;list<string> ls(0);typedef list<string>::iterator IT;vector<int> vs(0);typedef  vector<int>::iterator VT;for(int i=0;i<9;++i){getline(cin,input);ls.push_back(input);}for(IT it = ls.begin();it!=ls.end();++it){string buff;;stringstream stringin(*it);stringin >> buff;if(buff == "push"){int num = 0;stringin >> num;vs.push_back(num);cout << vs.size() << endl;}else if(buff == "pop"){if(vs.empty()){cout << -1 << endl;}else{VT vt = vs.end();--vt;cout << *vt << endl;vs.erase(vt);}}else if(buff == "get"){int num=0;stringin >> num;if((num > int(vs.size())) || (num<0)){cout << -1 << endl;}else{cout << vs[num] << endl;}}}return 0;
}

#include <iostream>
#include <string>
class A {public:A(std::string x = ""):_s(new std::string(x)){//构造函数}A(A&& that){//移动构造if(that._s != nullptr){_s=that._s;that._s = nullptr;}}~A(){//析构函数delete _s;}A& operator=(A&& that){//移动赋值if(this!=&that){std::string a = "";std::string* b = new std::string(a);if(_s != b){delete _s;_s = nullptr;}_s = new std::string;_s = that._s;delete b;}that._s=nullptr;return* this;}std::string s() const {return *_s;}private:std::string *_s;
};int main() {std::string input;std::cin >> input;A a(input);A b(std::move(a));std::cout << b.s() << std::endl;A c;c = std::move(b);std::cout << c.s() << std::endl;return 0;
}

#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
int main()
{stack<char> x;string input;int a = 0;getline(cin,input);const char* c = input.c_str();for(int i = 0;c[i]!='\0';++i){if(c[i]=='('){x.push(c[i]);}else if(c[i]=='['){x.push(c[i]);}else if(c[i]=='{'){x.push(c[i]);}else if(c[i]==')'){if(!x.empty()){if(x.top()=='('){x.pop();}else{--a;    }}else{--a;}}else if(c[i]==']'){if(!x.empty()){if(x.top()=='['){x.pop();}else{--a;    }}else{--a;}}else if(c[i]=='}'){if(!x.empty()){if(x.top()=='{'){x.pop();}else{--a;    }}else{--a;}}}if((x.size()==0)&&(a==0)){cout << "true" << endl;}else{cout <<"false" << endl;}return 0;
}

#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
int main()
{vector<int> vs;string input;getline(cin,input);stringstream s(input);int num;while(s>>num){vs.push_back(num);}typedef vector<int>::iterator IT;IT it1,it2,it3;for(it1=--(vs.end());it1!=vs.begin();--it1){it2=find(vs.begin(),it1,*it1);if(it2!=it1){vs.erase(it1);}}for(it3 = vs.begin();it3!=vs.end();++it3){cout << *it3  << " ";}cout << endl;return 0;
}

#include <iostream>
#include <list>
#include <sstream>
#include <algorithm>
using namespace std;
int main()
{string input;unsigned int num1;int num2;cin >> num1;cin.ignore();getline(cin,input);stringstream s(input);list<int> ls;typedef list<int>::iterator IT;while(s>>num2){if(ls.empty()){ls.push_front(num2);}else if(ls.size()>=num1){IT it = find(ls.begin(),ls.end(),num2);if(it!=ls.end()){ls.remove(*it); ls.push_front(num2);}else{ls.pop_back();ls.push_front(num2);}}else{ls.push_front(num2);}}for(IT it=ls.begin();it!=ls.end();++it){cout << *it << " ";}cout << endl;return 0;
}

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <list>
#include <vector>
#include <sstream>
using namespace std;int main()
{list<string>ls1,ls2;//存输入的数据,设置和查找typedef list<string>::iterator ItLs;vector<int>  vs_1,vs_2,vs_3;//存设置的数据范围,vs_3是查找vector<string> vs_s;//存城市位置typedef vector<int>::iterator ItVs_i;typedef vector<string>::iterator ItVs_s;list<vector<int> > ls_f;string input;int num;cin>>num;cin.ignore();for(int i =0;i<num;++i){getline(cin,input);ls1.push_back(input);}for(int i =0;i<num+1;++i){getline(cin,input);ls2.push_back(input);}for(ItLs it=ls1.begin();it!=ls1.end();++it){string s;stringstream ss(*it);ss >> s;char* c1 = new char[strlen(s.c_str())+1];strcpy(c1,s.c_str());char *sst1 = strtok(c1,".");vs_1.push_back(atoi(sst1));sst1 = strtok(NULL,".");vs_1.push_back(atoi(sst1));sst1 = strtok(NULL,".");vs_1.push_back(atoi(sst1));sst1 = strtok(NULL,".");vs_1.push_back(atoi(sst1));ss >> s;char* c2 = new char[strlen(s.c_str())+1];strcpy(c2,s.c_str());char *sst2 = strtok(c2,".");vs_2.push_back(atoi(sst2));sst2 = strtok(NULL,".");vs_2.push_back(atoi(sst2));sst2 = strtok(NULL,".");vs_2.push_back(atoi(sst2));sst2 = strtok(NULL,".");vs_2.push_back(atoi(sst2));ss >> s;vs_s.push_back(s);delete[] c1;delete[] c2;}for(ItLs it=ls2.begin();it!=ls2.end();++it){char* c1 = new char[strlen((*it).c_str())+1];strcpy(c1,(*it).c_str());char *sst1 = strtok(c1,".");vs_3.push_back(atoi(sst1));sst1 = strtok(NULL,".");vs_3.push_back(atoi(sst1));sst1 = strtok(NULL,".");vs_3.push_back(atoi(sst1));sst1 = strtok(NULL,".");vs_3.push_back(atoi(sst1));delete[] c1;}for(unsigned int a = 0;a<vs_3.size();a+=4){bool info=false;for(unsigned int b=0;b<vs_1.size();b+=4){if(vs_3[a]>=vs_1[b] && vs_3[a]<=vs_2[b]){if(vs_3[a+1]>=vs_1[b+1] && vs_3[a+1]<=vs_2[b+1]){if(vs_3[a+2]>=vs_1[b+2] && vs_3[a+2]<=vs_2[b+2]){if(vs_3[a+3]>=vs_1[b+3] && vs_3[a+3]<=vs_2[b+3]){cout << vs_s[b/4] << endl;info=true;}}}}}if(info==false){cout << "none" << endl;}}return 0;
}

#include <iostream>
#include <list>
#include <sstream>
using namespace std;
int main()
{list<int> ls;typedef list<int>::iterator IT;string input;int num;getline(cin,input);stringstream ss(input);while(ss >> num){ls.push_back(num);ls.sort(greater<int>());ls.unique();}int c = ls.size()<3?ls.size():3;IT it=ls.begin();for(int i =0;i<c;++i){cout << *it <<" ";++it;}cout << endl;return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>struct Point {int x;int y;bool operator < (Point & b){if(x==b.x)return y<b.y?true:false;elsereturn x<b.x;}
};int main() {int x = 0;int y = 0;std::vector<Point> vec;while (std::cin >> x >> y) {Point p;p.x = x;p.y = y;vec.push_back(p);}std::sort(vec.begin(), vec.end());for (auto iter = vec.begin(); iter != vec.end(); ++iter) {std::cout << iter->x << " " << iter->y << std::endl;}return 0;
}

#include <iostream>
#include <map>
#include <string>
void remove_elements(std::map<std::string, int> &m) {typedef  std::map<std::string, int>::iterator IT;for(IT it=m.begin();it!=m.end();++it){if((*it).second == 10){m.erase(it);}}
}int main() {std::map<std::string, int> m;std::string key;int val = 0;while (std::cin >> key >> val) {m[key] = val;}  remove_elements(m);for (const auto &ele : m) {std::cout << ele.first << " " << ele.second << std::endl;}  return 0;
}

牛客网题库公司真题 2021阅文C++方向笔试卷答案相关推荐

  1. 牛客网SQL大厂面试真题(二)

    SQL25 某宝店铺的SPU数量 SELECT style_id, COUNT(1) AS SPU_num FROM product_tb GROUP BY style_id ORDER BY SPU ...

  2. Java算法:牛客网腾讯笔试真题算法Java版1-11题

    题号 题目 知识点 难度 通过率 QQ1 生成格雷码 递归 简单 22.61%QQ2 微信红包 模拟 简单 25.61%QQ3 编码 字符串模拟 中等 26.60%QQ4 游戏任务标记 模拟 中等 3 ...

  3. 牛客网 PAT 算法历年真题 1003: 数素数 (20)

    1003:数素数 (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 令Pi表示第i个素数.现任给两个正整 ...

  4. Java算法:牛客网字节跳动笔试真题算法Java版1-27题

    题号 题目 知识点 难度 通过率 ZJ1 附加题 动态规划数组 中等 16.45% ZJ2 编程题1 贪心 中等 11.65% ZJ3 编程题2 字符串贪心 中等 29.30% ZJ4 附加题 递归模 ...

  5. Java算法:牛客网拼多多笔试真题算法Java版1-13题

    题号 题目 知识点 难度 通过率 PDD1 最大乘积 贪心模拟 中等 14.45%PDD2 大整数相乘 模拟 中等 27.32%PDD3 六一儿童节 贪心 中等 24.74%PDD4 迷宫寻路 模拟 ...

  6. 牛客网SQL大厂面试真题(一)

    SQL1 各个视频的平均完播率 SELECT log.video_id, ROUND(SUM(IF(TIMESTAMPDIFF(SECOND, log.start_time, log.end_time ...

  7. 牛客网 SQL大厂面试真题篇 SQL2 平均播放进度大于60%的视频类别

    描述 用户-视频互动表tb_user_video_log id uid video_id start_time end_time if_follow if_like if_retweet commen ...

  8. 牛客网 SQL大厂面试真题篇 SQL5 国庆期间每类视频点赞量和转发量

    描述 用户-视频互动表tb_user_video_log id uid video_id start_time end_time if_follow if_like if_retweet commen ...

  9. 牛客网 SQL大厂面试真题篇 SQL3 每类视频近一个月的转发量/率

    描述 用户-视频互动表tb_user_video_log id uid video_id start_time end_time if_follow if_like if_retweet commen ...

最新文章

  1. char的测试和含义
  2. 利用networkx求解网络的重叠度
  3. bash内部命令-1
  4. mc服务器天赋系统,[娱乐|经济]GokiStats——全新的天赋系统插件MySQL可用[全版本]...
  5. 5天学python_人生苦短,我将学习Python基本句子(第5天),我学,基础,篇,语句,Day5...
  6. 实地踩坑,新鲜出炉,阿里云GPU服务器Centos7.7深度学习环境搭建实战
  7. 【全网最全面C语言教程】C语言从入门到精通
  8. 计算机技术在中医领域的应用,计算机技术在中医药领域的应用概况.doc
  9. 利用ESP8266与米思齐从零制作模拟温室大棚--接线篇
  10. 浅谈图像识别技术原理与价值
  11. ES mapping
  12. 用html做龙卷风特效,抖音HTML龙卷风特效代码是啥?
  13. 软件分析与测试研讨会,第四届Vector测试专题研讨会
  14. CSS 样式书写规范,css样式书写规范
  15. android 手机录屏功能,手机自带录屏功能在哪里找?轻松搞定屏幕录制
  16. Debian权威发音
  17. yolov5模型的部署之TensorRT
  18. CAMs激活图可视化系列——GradCAM
  19. 持续集成工具TeamCity快速入门
  20. 记一次北航软件学院复试

热门文章

  1. 营销型网站的概念及设计制作过程中的注意事项
  2. grpc-gateway插件:让客户端通过调http接口来远程调用grpc服务
  3. 校园寝室管理系统-“轻舟校园”助力校园实现信息化、智能化管理
  4. 计算机在语文教学中的用场,信息技术在语文教学中的作用
  5. 默认计算机网络密码是多少,tplogin.cn初始密码是多少 tplogin管理密码一般是多少...
  6. 自动驾驶系统2.0:安全展望
  7. 【数字化】推动5大层面变革——BCG和MIT帮你设计卓越数字化组织
  8. 现场直击汶川地震都江堰灾情(图)
  9. 兄dei,帮我开一下门吧~
  10. 教你用scratch2.0编见缝插针游戏