当前位置:网站首页>Delete some elements in the array
Delete some elements in the array
2022-07-05 17:49:00 【-Ximen blowing snow】
The requirements are described as follows
- A top-level pointer points to a structure
CCPointsArray , It's stored here n Structures - Given another structure
PointArray - from 1 Delete array from 2 Elements that meet the conditions in
The code implementation is as follows :
#include <iostream>
#include <memory>
#include <string.h>
using namespace std;
typedef struct {
int x;
int y;
} Point;
typedef struct {
Point point;
int Times;
} CCPoints;
int main() {
int n;
CCPoints aa[10];
for (int i = 0; i < 10; i++) {
aa[i].point = {
i, i};
aa[i].Times = i + 2;
}
for (int i = 0; i < 10; i++) {
cout << "i = " << i << " " << aa[i].point.x << " " << aa[i].point.y
<< " " << aa[i].Times << endl;
}
cout << endl;
const CCPoints* bb = aa;
Point tt[3];
tt[0] = {
2, 2};
tt[1] = {
4, 4};
tt[2] = {
7, 7};
auto* cc = new CCPoints[10];
for(int i = 0 ;i<10;i++){
cc[i].point = {
bb[i].point.x,bb[i].point.y};
cc[i].Times = bb[i].Times;
}
int ps2 = 0, cnts = 0;
int j = 0;
int len = 10;
for (int ps = 0; ps < 3; ps++) {
ps2 = 0;
for (int cs = 0; cs < len; cs++) {
if (cc[cs].point.x != tt[ps].x || cc[cs].point.y != tt[ps].y) {
cc[ps2] = cc[cs];
ps2++;
}else{
cnts++;
}
}
}
cout << " cnts " << cnts << endl << endl << endl;
for (int i = 0; i < len-3; i++) {
cout << " i " << cc[i].point.x << " " << cc[i].point.y << " "
<< cc[i].Times << endl;
}
delete[] cc;
}
Running results
i = 0 0 0 2
i = 1 1 1 3
i = 2 2 2 4
i = 3 3 3 5
i = 4 4 4 6
i = 5 5 5 7
i = 6 6 6 8
i = 7 7 7 9
i = 8 8 8 10
i = 9 9 9 11
cnts 3
i 0 0 2
i 1 1 3
i 3 3 5
i 5 5 7
i 6 6 8
i 8 8 10
i 9 9 11
Reference resources : Deletes the specified element from the array ——C++ Realization
边栏推荐
猜你喜欢

Mongodb (quick start) (I)

职场进阶指南:大厂人必看书籍推荐

Seven Devops practices to improve application performance

ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise

解决“双击pdf文件,弹出”请安装evernote程序

Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?

統計php程序運行時間及設置PHP最長運行時間

漏洞复现----48、Airflow dag中的命令注入(CVE-2020-11978)

云主机oracle异常恢复----惜分飞

GFS分布式文件系统
随机推荐
Cartoon: looking for the k-th element of an unordered array (Revised)
Knowing that his daughter was molested, the 35 year old man beat the other party to minor injury level 2, and the court decided not to sue
VBA drives SAP GUI to realize office automation (II): judge whether elements exist
Redis+caffeine two-level cache enables smooth access speed
使用QT设计师界面类创建2个界面,通过按键从界面1切换到界面2
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
Redis基础
Read libco save and restore the on-site assembly code
How to save the trained neural network model (pytorch version)
Rider set the highlighted side of the selected word, remove the warning and suggest highlighting
Kafaka technology lesson 1
力扣解法汇总1200-最小绝对差
普通程序员看代码,顶级程序员看趋势
Six bad safety habits in the development of enterprise digitalization, each of which is very dangerous!
世界上最难的5种编程语言
IDEA 项目启动报错 Shorten the command line via JAR manifest or via a classpath file and rerun.
ITK Example
Tita 绩效宝:如何为年中考核做准备?
Humi analysis: the integrated application of industrial Internet identity analysis and enterprise information system
Cmake tutorial step6 (add custom commands and generate files)