当前位置:网站首页>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
边栏推荐
- Cartoon: interesting [pirate] question
- 读libco保存恢复现场汇编代码
- Database design in multi tenant mode
- Tita 绩效宝:如何为年中考核做准备?
- Vulnerability recurrence - 48. Command injection in airflow DAG (cve-2020-11978)
- LeetCode每日一题:合并两个有序数组
- 北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
- Accuracy of BigDecimal Division
- 漫画:有趣的【海盗】问题
- Cmake tutorial step6 (add custom commands and generate files)
猜你喜欢

Ten top automation and orchestration tools

Oracle Recovery Tools ----oracle数据库恢复利器

Cmake tutorial Step2 (add Library)

Count the running time of PHP program and set the maximum running time of PHP

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

ELK日志分析系统

Anaconda中配置PyTorch环境——win10系统(小白包会)

Thesis reading_ Chinese NLP_ LTP

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

Kafaka technology lesson 1
随机推荐
7 pratiques devops pour améliorer la performance des applications
企业数字化发展中的六个安全陋习,每一个都很危险!
Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP
提高应用程序性能的7个DevOps实践
ELK日志分析系统
Is it safe to open an account online? What is the general interest rate of securities financing?
如何修改mysql字段为自增长字段
Tita performance treasure: how to prepare for the mid year examination?
Short the command line via jar manifest or via a classpath file and rerun
Cmake tutorial Step4 (installation and testing)
To solve the problem of "double click PDF file, pop up", please install Evernote program
Database design in multi tenant mode
VBA drives SAP GUI to realize office automation (II): judge whether elements exist
Kafaka technology lesson 1
Customize the theme of matrix (I) night mode
QT控制台打印输出
Mongodb (quick start) (I)
数据访问 - EntityFramework集成
「运维有小邓」用于云应用程序的单点登录解决方案
EPM相关