当前位置:网站首页>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
CCPoints
Array , It's stored here n Structures - Given another structure
Point
Array - 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
边栏推荐
- 统计php程序运行时间及设置PHP最长运行时间
- ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
- Simple query cost estimation
- Is it safe to open an account online? What is the general interest rate of securities financing?
- Read libco save and restore the on-site assembly code
- Ordinary programmers look at the code, and top programmers look at the trend
- Cartoon: interesting [pirate] question
- 漫画:有趣的海盗问题 (完整版)
- Cartoon: how to multiply large integers? (integrated version)
- Which platform of outer disk gold is regular and safe, and how to distinguish it?
猜你喜欢
云主机oracle异常恢复----惜分飞
mongodb(快速上手)(一)
CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计
Winedt common shortcut key modify shortcut key latex compile button
解决“双击pdf文件,弹出”请安装evernote程序
MATLAB查阅
To solve the problem of "double click PDF file, pop up", please install Evernote program
LeetCode 练习——206. 反转链表
Mongodb (quick start) (I)
十个顶级自动化和编排工具
随机推荐
读libco保存恢复现场汇编代码
Teamcenter 消息注册前操作或后操作
Webapp development - Google official tutorial
Mongodb (quick start) (I)
QT控制台打印输出
leetcode每日一练:旋转数组
Cmake tutorial Step4 (installation and testing)
Troubleshooting - about clip not found Visual Studio
云主机oracle异常恢复----惜分飞
Mysql5.6 parsing JSON strings (supporting complex nested formats)
Mask wearing detection based on yolov3
Knowledge points of MySQL (7)
较文心损失一点点性能提升很多
Data access - entityframework integration
十个顶级自动化和编排工具
提高应用程序性能的7个DevOps实践
Why is all (()) true and any (()) false?
7 pratiques devops pour améliorer la performance des applications
What are the requirements for PMP certification? How much is it?
LeetCode 练习——206. 反转链表