当前位置:网站首页>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
边栏推荐
- tkinter窗口预加载
- Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
- Winedt common shortcut key modify shortcut key latex compile button
- Clickhouse (03) how to install and deploy Clickhouse
- Which platform of outer disk gold is regular and safe, and how to distinguish it?
- Sentinel flow guard
- Matlab reference
- Cartoon: looking for the best time to buy and sell stocks
- This 17-year-old hacker genius cracked the first generation iPhone!
- ITK Example
猜你喜欢
EPM related
Short the command line via jar manifest or via a classpath file and rerun
Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
VBA drives SAP GUI to realize office automation (II): judge whether elements exist
PMP认证需具备哪些条件啊?费用多少啊?
To solve the problem of "double click PDF file, pop up", please install Evernote program
基于YOLOv3的口罩佩戴检测
神经网络自我认知模型
Count the running time of PHP program and set the maximum running time of PHP
MySQL之知识点(七)
随机推荐
职场进阶指南:大厂人必看书籍推荐
企业数字化发展中的六个安全陋习,每一个都很危险!
QT控制台打印输出
提高应用程序性能的7个DevOps实践
How to modify MySQL fields as self growing fields
Cartoon: looking for the best time to buy and sell stocks
漏洞复现----48、Airflow dag中的命令注入(CVE-2020-11978)
Cmake tutorial step6 (add custom commands and generate files)
请问下为啥有的表写sql能查到数据,但在数据地图里查不到啊,查表结构也搜不到
Why is all (()) true and any (()) false?
2022年信息系统管理工程师考试大纲
Six bad safety habits in the development of enterprise digitalization, each of which is very dangerous!
漫画:如何实现大整数相乘?(整合版)
Cmake tutorial Step3 (requirements for adding libraries)
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
ELK日志分析系统
统计php程序运行时间及设置PHP最长运行时间
Cartoon: how to multiply large integers? (next)
ITK Example
证券网上开户安全吗?证券融资利率一般是多少?