当前位置: 首页 > news >正文

2020C++等级考试二级真题题解

 202012数组指定部分逆序重放c++
 

#include <iostream>
using namespace std;
int main() {int a[110];int n, k;cin >> n >> k;for (int i = 0; i < n; i++) {cin >> a[i];}for (int i = 0; i < k / 2; i++) {swap(a[i], a[k - 1 - i]);}for (int i = 0; i < n; i++) {cout << a[i] << " ";}return 0;
}

202012简单密码c++
 

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {char a[220];gets(a);for (int i = 0; i < strlen(a); i++) {if (a[i] >= 'A' && a[i] <= 'E') {a[i] = a[i] + 21;} else if (a[i] >= 'F' && a[i] <= 'Z') {a[i] = a[i] - 5;}}cout << a;return 0;
}

 202012错误探测c++
 

#include <iostream>
using namespace std;void shuru();
void tongji1();
int a[110][110] = { 0 };
int n;int main() {shuru();tongji1();int cnt1 = 0;  //奇数列的个数int x = 0;for (int i = 1; i <= n; i++)  //统计奇数列有几个{if (a[0][i] % 2 != 0) {cnt1++;x = i;}}int cnt2 = 0;  //奇数行的个数int y = 0;for (int i = 1; i <= n; i++)  //统计奇数行有几个{if (a[i][0] % 2 != 0) {cnt2++;y = i;}}if (cnt1 == 0 && cnt2 == 0) {cout << "OK" << endl;} else if (cnt1 == 1 && cnt2 == 1) {cout << y << " " << x << endl;} else if (cnt1 > 1 || cnt2 > 1) {cout << "Corrupt" << endl;}return 0;
}
void shuru() {cin >> n;for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {cin >> a[i][j];}}
}
void tongji1() {for (int i = 1; i <= n; i++)  //行{for (int j = 1; j <= n; j++)  //列{if (a[i][j] == 1) {a[i][0]++;  //对应行头(0)位置++a[0][j]++;  //对应列头(0)位置++}}}
}

 202012奇数单增序列c++
 

#include <iostream>
using namespace std;
int a[510];
int la = 0;
int main() {int n;cin >> n;for (int i = 0; i < n; i++) {int s;cin >> s;if (s % 2 == 1) {a[la] = s;la++;}}for (int i = 0; i < la - 1; i++) {for (int j = 0; j < la - 1 - i; j++) {if (a[j] > a[j + 1]) {swap(a[j], a[j + 1]);}}}for (int i = 0; i < la; i++) {if (i != la - 1)  cout << a[i] << ",";else cout << a[i];}return 0;
}

 202012话题焦点人物c++
 

#include <iostream>
using namespace std;
int a[10010];
int b[10010][30];
int cnt[110];
int main() {int n;cin >> n;for (int i = 0; i < n; i++) {cin >> a[i];cin >> b[i][0];for (int j = 1; j <= b[i][0]; j++) {cin >> b[i][j];cnt[b[i][j]]++;}}int ma = -1;int mai = -1;for (int i = 0; i <= 100; i++) {if (cnt[i] > 0) {if (ma < cnt[i]) {ma = cnt[i];mai = i;}}}cout << mai << endl;int cnt2[10010] = { 0 };for (int i = 0; i < n; i++) {for (int j = 1; j <= b[i][0]; j++) {if (b[i][j] == mai) {cnt2[a[i]]++;}}}for (int i = 0; i <= 10000; i++) {if (cnt2[i] > 0) {cout << i << " ";}}return 0;
}

 

 202009单词倒排c++

#include <iostream>
#include <string>
using namespace std;
string a[1010];
int la = 0;
void addstring(string);
void sortstring();
int main() {string s;getline(cin, s);int ls = s.size();int cnt = 0;for (int i = 0; i < ls + 1; i++) {if (s[i] == ' ' || s[i] == '\0') {if (cnt != 0) {string tmp = s.substr(i - cnt, cnt);a[la++] = tmp;}cnt = 0;} else if (s[i] != ' ') {cnt++;}}for (int i = la - 1; i >= 0; i--) {cout << a[i] << " ";}return 0;
}


 

202009细菌的繁殖与扩散c++
 

#include <iostream>
using namespace std;
int a[11][11] = { 0 };
int b[11][11] = { 0 };
int m, d;
void aCopyTob();
void bCopyToa();
void showa();
void showb();
int main() {cin >> m >> d;a[5][5] = m;for (int k = 0; k < d; k++) {// 1.a复制到baCopyTob();// 2.a死亡,b复制到abCopyToa();}// 3.显示showa();return 0;
}
void aCopyTob() {//右下左上 右下  左下 右上 左上int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };for (int i = 1; i <= 9; i++) {for (int j = 1; j <= 9; j++) {if (a[i][j] != 0) {for (int k = 0; k < 8; k++) {int tx = i + dx[k];int ty = j + dy[k];if (tx >= 1 && tx <= 9 && ty >= 1 && ty <= 9) {b[tx][ty] = b[tx][ty] + a[i][j] * 1;}}b[i][j] = b[i][j] + a[i][j] * 2;}}}
}
void bCopyToa() {for (int i = 1; i <= 9; i++) {for (int j = 1; j <= 9; j++) {a[i][j] = b[i][j];b[i][j] = 0;}}
}
void showa() {for (int i = 1; i <= 9; i++) {for (int j = 1; j <= 9; j++) {cout << a[i][j] << " ";}cout << endl;}
}
void showb() {for (int i = 1; i <= 9; i++) {for (int j = 1; j <= 9; j++) {cout << b[i][j] << " ";}cout << endl;}
}

 202009高精度加法c++

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
string myadd(string, string);
int main() {string a, b;cin >> a >> b;cout << myadd(a, b);return 0;
}
string myadd(string s1, string s2) {int a[1000] = { 0 };int la = s1.size();for (int i = 0; i < la; i++) {a[la - 1 - i] = s1[i] - 48;}int b[1000] = { 0 };int lb = s2.size();for (int i = 0; i < lb; i++) {b[lb - 1 - i] = s2[i] - 48;}for (int i = 0; i < max(la, lb); i++) {a[i] = a[i] + b[i];if (a[i] >= 10) {a[i + 1] = a[i + 1] + 1;a[i] = a[i] - 10;}}int p = -1;for (int i = max(la, lb) + 1; i >= 0; i--) {if (a[i] != 0) {p = i;break;}}string s = "";for (int i = 0; i <= p; i++) {s = char(a[i] + 48) + s;}return s;
}


 

202009合影效果c++
 

#include <iostream>
#include <iomanip>
#include <string.h>
using namespace std;
int main() {char a[50][20];float b[50];char cache[50];int n;cin >> n;for (int i = 0; i < n; i++) {cin >> a[i] >> b[i];}for (int i = 0; i < n - 1; i++) {for (int j = 0; j < n - 1 - i; j++) {if (a[j][0] == 'f' && a[j + 1][0] == 'm') {strcpy(cache, a[j]);strcpy(a[j], a[j + 1]);strcpy(a[j + 1], cache);swap(b[j], b[j + 1]);} else if (a[j][0] == 'm' && a[j + 1][0] == 'm' && b[j] > b[j + 1]) {strcpy(cache, a[j]);strcpy(a[j], a[j + 1]);strcpy(a[j + 1], cache);swap(b[j], b[j + 1]);} else if (a[j][0] == 'f' && a[j + 1][0] == 'f' && b[j] < b[j + 1]) {strcpy(cache, a[j]);strcpy(a[j], a[j + 1]);strcpy(a[j + 1], cache);swap(b[j], b[j + 1]);}}}for (int i = 0; i < n; i++) {cout << fixed << setprecision(2) << b[i] << " ";}return 0;
}

202009循环数c++
 

#include <iostream>
#include <string>
using namespace std;
string cheng(string, int);int main() {// cout<<cheng("5046766555",2)<<endl;string a;cin >> a;string na = a + a;// cout<<na<<endl;int len = a.size();for (int i = 1; i <= len; i++) {string s = cheng(a, i);// cout<<s<<endl;if (na.find(s) == string::npos) {cout << 0;return 0;}}cout << 1;return 0;
}
string cheng(string n, int a) {int na[1000] = { 0 };int l = n.size();for (int i = 0; i < l; i++) {na[i] = n[l - 1 - i] - 48;}for (int i = 0; i < l; i++) {na[i] = na[i] * a;}for (int i = 0; i < l + 70; i++) {if (na[i] >= 10) {na[i + 1] = na[i + 1] + na[i] / 10;na[i] = na[i] % 10;}}int p = 0;for (int i = l + 70; i >= 0; i--) {if (na[i] != 0) {p = i;break;}}string r = "";for (int i = 0; i <= p; i++) {r = (char)(na[i] + 48) + r;}return r;
}

202006计算矩阵边缘元素之和c++
 

#include <iostream>
#include <string>
using namespace std;int main() {int sum = 0;int m, n;cin >> n >> m;for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {int a;cin >> a;if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {sum = sum + a;}}}cout << sum;return 0;
}

202006最长最短单词c++
 

#include <iostream>
#include <string.h>
using namespace std;
int main() {char a[20000];cin.getline(a, 20000);int cnt = 0;int maxCnt = 0;int minCnt = 301;int maxSp = 0;int minSp = 301;int len = strlen(a);for (int i = 0; i < len + 1; i++) {if (a[i] != ' ' && a[i] != ',') {cnt++;} else if (cnt > 0) {if (maxCnt < cnt) {maxCnt = cnt;maxSp = i - cnt;}if (minCnt > cnt) {minCnt = cnt;minSp = i - cnt;}cnt = 0;}}for (int i = maxSp; i < maxCnt + maxSp; i++) {cout << a[i];}cout << endl;for (int i = minSp; i < minCnt + minSp; i++) {cout << a[i];}return 0;
}

 202006啤酒厂选址c++
 

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int a[10020];  //正方向距离
int c[10010];  //啤酒
int n;
int main() {system("chcp 65001");cin >> n;for (int i = 1; i <= n; i++) {cin >> c[i - 1] >> a[i];}for (int i = 1; i <= n; i++)  //利用前缀和{a[i] = a[i] + a[i - 1];}int mi = 999999999;int mii = -1;for (int i = 0; i < n; i++) {int sum = 0;for (int j = 0; j < n; j++) {int t1 = abs(a[j] - a[i]);int t2 = abs(a[n] - t1);int juli = min(t1, t2);sum = sum + juli * c[j];}if (sum < mi) {mi = sum;mii = i;}}cout << mii << "," << mi << endl;return 0;
}

202006统计误差范围内的数c++
 

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a[100];
int n, x, c;
int main() {cin >> n;for (int i = 0; i < n; i++) {cin >> a[i];}cin >> x >> c;int cnt = 0;for (int i = 0; i < n; i++) {if (abs(a[i] - x) <= c) {cnt++;}}cout << cnt;return 0;
}

202006单词排序c++

#include <iostream>
#include <string>
using namespace std;
string a[1010];
int la = 0;
void addstring(string);
void sortstring();
int main() {string s;getline(cin, s);int ls = s.size();int cnt = 0;for (int i = 0; i < ls + 1; i++) {if (s[i] == ' ' || s[i] == '\0') {if (cnt != 0) {string tmp = s.substr(i - cnt, cnt);addstring(tmp);}cnt = 0;} else if (s[i] != ' ') {cnt++;}}sortstring();for (int i = 0; i < la; i++) {cout << a[i] << endl;}return 0;
}
void addstring(string t) {for (int i = 0; i < la; i++) {if (a[i] == t)return;}a[la++] = t;
}
void sortstring() {for (int i = 0; i < la - 1; i++) {for (int j = 0; j < la - 1 - i; j++) {if (a[j] > a[j + 1]) {swap(a[j], a[j + 1]);}}}
}

相关文章:

2020C++等级考试二级真题题解

202012数组指定部分逆序重放c #include <iostream> using namespace std; int main() {int a[110];int n, k;cin >> n >> k;for (int i 0; i < n; i) {cin >> a[i];}for (int i 0; i < k / 2; i) {swap(a[i], a[k - 1 - i]);}for (int i 0…...

面试官:聊聊 nextTick

前言 在最近的面试中,不少面试官叫我聊聊 nextTick,nextTick 是个啥,这篇文章咱来好好聊聊! 我的回答 nextTick 是官方提供的一个异步方法,用于在 DOM 更新之后执行回调。正好在我的项目中用到了,就拿它来形容一下,大概的场景是渲染一个列表,每次点击按钮就会往列表后…...

shell编程之条件语句(shell脚本)

条件测试操作 要使shell脚本程序具备一定的“智能”,面临的第一个问题就是如何区分不同的情况以确定执行何种操作。例如,当磁盘使用率超过95%时,发送告警信息;当备份目录不存在时,能够自动创建;当源码编译程序时,若配置失败则不再继续安装等。 shell环境根据命令执行后…...

QT中QSettings的使用系列之二:保存和恢复应用程序主窗口

1、核心代码 #include "widget.h" #include "ui_widget.h" #include <QSettings> #include <QDebug> #include <QColo...

Linux系统上安装Miniconda并安装特定版本的Python

要在Linux系统上安装Miniconda并安装特定版本的Python&#xff08;例如3.10.12&#xff09;&#xff0c;请按照以下步骤进行操作&#xff1a; 1. 下载并安装Miniconda 下载Miniconda安装脚本&#xff1a; 使用wget或curl下载Miniconda安装脚本。以下是使用wget的命令&#xff…...

解决Qt中 -lGL无法找到的问题

在使用Qt Creator创建并编译新项目时&#xff0c;可能会遇到以下错误&#xff1a; /usr/bin/ld: cannot find -lGL collect2: error: ld returned 1 exit status make: *** [untitled1] Error 1 18:07:41: The process "/usr/bin/make" exited with code 2. Error w…...

【重要】《HTML趣味编程》专栏内资源的下载链接

目录 关于专栏 博主简介 专栏内资源的下载链接 写在后面 关于专栏 本专栏将持续更新,至少含有30个案例,后续随着案例的增加可能会涨价,欢迎大家尽早订阅!(订阅后可查看专栏内所有文章,并且可以下载专栏内的所有资源) 博主简介 ⭐ 2024年百度文心智能体大赛 Top1⭐…...

苍穹外卖环境搭建

一、前端环境搭建 ①整体结构 ②前端工程基于nginx运行 启动nginx:双击 nginx.exe 即可启动 nginx 服务&#xff0c;访问端口号为 80 进入浏览器地址输入locallhost回车 二、后端环境搭建 后端初始工程基于maven进行项目构建&#xff0c;并且进行分模块开发 (1) idea打开初始…...

切割游戏介绍

简介 上大学时&#xff0c;在学校实验室里玩过一个貌似使用VC写的小游戏&#xff0c;一个小球在界面上四处游荡&#xff0c;玩家使用鼠标切割背景&#xff0c;将背景切割剩余到一定的百分比后&#xff0c;就胜利了&#xff0c;后边的背景图会全部展示出来。 使用qt的qml技术&a…...

对接Paypal、Stripe支付简单流程

一、Stripe卡支付简单流程&#xff1a; #mermaid-svg-bZxQh1bt4Z8agjJg {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-bZxQh1bt4Z8agjJg .error-icon{fill:#552222;}#mermaid-svg-bZxQh1bt4Z8agjJg .error-text{fi…...

微服务中不同服务使用openfeign 相互调用

首先 我们上文 已经知道了 nacos 的注册服务&#xff0c;现在 我们 在不同服务中相互调用就可以使用openfeign 直接调用&#xff0c;而不是 再写冗余的调用代码啦 首先 我们的微服务组件如下 因为我这个微服务是我在 员工登录demo 中 拆出来的&#xff0c;在userlogin模块中…...

社区项目-项目介绍环境搭建

文章目录 1.技术选型2.原型设计1.安装AxureRP2.进行汉化3.载入元件库4.基本设计 3.元数建模1.安装元数建模软件2.新建项目3.新增一个刷题模块主题域4.新增数据表 subject_category5.新增关系图&#xff0c;将表拖过来6.新增题目标签表7.新增题目信息表8.新增单选表、多选表、判…...

【论文阅读】-- Omnisketch:高效的多维任意谓词高速流分析

Omnisketch&#xff1a;高效的多维任意谓词高速流分析 摘要1 引言2 预备知识及相关工作3 OMNISKETCH&#xff1a;使用任意谓词估计频率3.1 Sketch S0&#xff1a;Count-Min with rid-sets 用于估计带有谓词的查询3.2 Sketch S1 &#xff08;OmniSketch&#xff09;&#xff1a;…...

【ajax核心03】封装底层axios函数

目录 一&#xff1a;步骤总结 二&#xff1a;获取数据需求&#xff1a; 三&#xff1a;查找数据需求&#xff1a; 四&#xff1a;发送数据需求&#xff1a; 一&#xff1a;步骤总结 定义myAxios函数&#xff0c;接收配置对象&#xff0c;返回Promise对象发送XHR请求&#…...

python科学计算

文章目录 一、科学计算介绍二、NumPy2.1、NumPy是什么2.2、NumPy使用场景2.3、NumPy特点2.4、NumPy如何使用 三、数组3.1、数组介绍3.2、创建数组3.3、数组的大小3.4、通过索引访问数组3.5、变换数组的形态3.6、常用的ufunc运算 一、科学计算介绍 python语言提供了array模块&am…...

Leetcode - 132双周赛

目录 一、3174. 清除数字 二、3175. 找到连续赢 K 场比赛的第一位玩家 三、3176. 求出最长好子序列 I 四、3177. 求出最长好子序列 II 一、3174. 清除数字 本题可以使用栈来模拟&#xff0c;遇到数字弹出栈顶元素&#xff0c;遇到字母入栈。 代码如下&#xff1a; //使用字…...

Mongodb在UPDATE操作中使用$push向数组中插入数据

学习mongodb&#xff0c;体会mongodb的每一个使用细节&#xff0c;欢迎阅读威赞的文章。这是威赞发布的第69篇mongodb技术文章&#xff0c;欢迎浏览本专栏威赞发布的其他文章。如果您认为我的文章对您有帮助或者解决您的问题&#xff0c;欢迎在文章下面点个赞&#xff0c;或者关…...

ArcGIS JSAPI 高级教程 - ArcGIS Maps SDK for JavaScript - 锐化效果

ArcGIS JSAPI 高级教程 - ArcGIS Maps SDK for JavaScript - 锐化效果 核心代码完整代码在线示例ArcGIS Maps SDK for JavaScript 从 4.29 开始增加 RenderNode 类,可以添加数据以及操作 FBO(ManagedFBO); 通过操作 FBO,可以通过后处理实现很多效果,官方提供了几个示例,…...

信息系统项目管理师 | 信息系统安全技术

关注WX&#xff1a;CodingTechWork 信息安全概念 安全属性 秘密性&#xff1a;信息不被未授权者知晓。完整性&#xff1a;信息是正确的、真实的、未被篡改的、完整无缺。可用性&#xff1a;信息可以随时正常使用。 安全分层 设备安全 设备的稳定性&#xff1a;在一定时间…...

Java数据类型与运算符

1. 变量和类型 变量指的是程序运行时可变的量&#xff0c;相当于开辟一块空间来保存一些数据。 类型则是对变量的种类进行了划分&#xff0c;不同类型的变量具有不同的特性。 1.1 整型变量&#xff08;重点&#xff09; 基本语法格式&#xff1a; int 变量名 初始值;代码示…...

React 第五十五节 Router 中 useAsyncError的使用详解

前言 useAsyncError 是 React Router v6.4 引入的一个钩子&#xff0c;用于处理异步操作&#xff08;如数据加载&#xff09;中的错误。下面我将详细解释其用途并提供代码示例。 一、useAsyncError 用途 处理异步错误&#xff1a;捕获在 loader 或 action 中发生的异步错误替…...

反向工程与模型迁移:打造未来商品详情API的可持续创新体系

在电商行业蓬勃发展的当下&#xff0c;商品详情API作为连接电商平台与开发者、商家及用户的关键纽带&#xff0c;其重要性日益凸显。传统商品详情API主要聚焦于商品基本信息&#xff08;如名称、价格、库存等&#xff09;的获取与展示&#xff0c;已难以满足市场对个性化、智能…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院查看报告小程序

一、开发环境准备 ​​工具安装​​&#xff1a; 下载安装DevEco Studio 4.0&#xff08;支持HarmonyOS 5&#xff09;配置HarmonyOS SDK 5.0确保Node.js版本≥14 ​​项目初始化​​&#xff1a; ohpm init harmony/hospital-report-app 二、核心功能模块实现 1. 报告列表…...

IoT/HCIP实验-3/LiteOS操作系统内核实验(任务、内存、信号量、CMSIS..)

文章目录 概述HelloWorld 工程C/C配置编译器主配置Makefile脚本烧录器主配置运行结果程序调用栈 任务管理实验实验结果osal 系统适配层osal_task_create 其他实验实验源码内存管理实验互斥锁实验信号量实验 CMISIS接口实验还是得JlINKCMSIS 简介LiteOS->CMSIS任务间消息交互…...

Python ROS2【机器人中间件框架】 简介

销量过万TEEIS德国护膝夏天用薄款 优惠券冠生园 百花蜂蜜428g 挤压瓶纯蜂蜜巨奇严选 鞋子除臭剂360ml 多芬身体磨砂膏280g健70%-75%酒精消毒棉片湿巾1418cm 80片/袋3袋大包清洁食品用消毒 优惠券AIMORNY52朵红玫瑰永生香皂花同城配送非鲜花七夕情人节生日礼物送女友 热卖妙洁棉…...

vue3 daterange正则踩坑

<el-form-item label"空置时间" prop"vacantTime"> <el-date-picker v-model"form.vacantTime" type"daterange" start-placeholder"开始日期" end-placeholder"结束日期" clearable :editable"fal…...

6个月Python学习计划 Day 16 - 面向对象编程(OOP)基础

第三周 Day 3 &#x1f3af; 今日目标 理解类&#xff08;class&#xff09;和对象&#xff08;object&#xff09;的关系学会定义类的属性、方法和构造函数&#xff08;init&#xff09;掌握对象的创建与使用初识封装、继承和多态的基本概念&#xff08;预告&#xff09; &a…...

海云安高敏捷信创白盒SCAP入选《中国网络安全细分领域产品名录》

近日&#xff0c;嘶吼安全产业研究院发布《中国网络安全细分领域产品名录》&#xff0c;海云安高敏捷信创白盒&#xff08;SCAP&#xff09;成功入选软件供应链安全领域产品名录。 在数字化转型加速的今天&#xff0c;网络安全已成为企业生存与发展的核心基石&#xff0c;为了解…...

DeepSeek越强,Kimi越慌?

被DeepSeek吊打的Kimi&#xff0c;还有多少人在用&#xff1f; 去年&#xff0c;月之暗面创始人杨植麟别提有多风光了。90后清华学霸&#xff0c;国产大模型六小虎之一&#xff0c;手握十几亿美金的融资。旗下的AI助手Kimi烧钱如流水&#xff0c;单月光是投流就花费2个亿。 疯…...

深度解析:etcd 在 Milvus 向量数据库中的关键作用

目录 &#x1f680; 深度解析&#xff1a;etcd 在 Milvus 向量数据库中的关键作用 &#x1f4a1; 什么是 etcd&#xff1f; &#x1f9e0; Milvus 架构简介 &#x1f4e6; etcd 在 Milvus 中的核心作用 &#x1f527; 实际工作流程示意 ⚠️ 如果 etcd 出现问题会怎样&am…...