当前位置:网站首页>删除数组中的某几个元素
删除数组中的某几个元素
2022-07-05 17:23:00 【-西门吹雪】
需求描述如下
- 一个顶层指针指向一个结构体
CCPoints数组,这里存放了n个结构 - 给定一个另外一个结构体
Point数组 - 从1中删除数组2中的满足条件的元素
代码实现如下:
#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;
}
运行结果
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
边栏推荐
- Ordinary programmers look at the code, and top programmers look at the trend
- Teamcenter 消息注册前操作或后操作
- ICML 2022 | Meta提出魯棒的多目標貝葉斯優化方法,有效應對輸入噪聲
- Ten top automation and orchestration tools
- 基于YOLOv3的口罩佩戴检测
- 服务器配置 jupyter环境
- Tita performance treasure: how to prepare for the mid year examination?
- 蚂蚁金服的暴富还未开始,Zoom的神话却仍在继续!
- Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition
- Force deduction solution summary 1200 minimum absolute difference
猜你喜欢

Ten top automation and orchestration tools

服务器配置 jupyter环境

Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP

Seven Devops practices to improve application performance

Machine learning 02: model evaluation
Complete solution instance of Oracle shrink table space

C # mixed graphics and text, written to the database in binary mode

Knowledge points of MySQL (6)

Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition

企业数字化发展中的六个安全陋习,每一个都很危险!
随机推荐
ICML 2022 | Meta提出魯棒的多目標貝葉斯優化方法,有效應對輸入噪聲
7 pratiques devops pour améliorer la performance des applications
Cartoon: how to multiply large integers? (next)
PMP认证需具备哪些条件啊?费用多少啊?
Kafaka技术第一课
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
Size_t 是无符号的
漫画:寻找股票买入卖出的最佳时机
Mongodb (quick start) (I)
2022 information system management engineer examination outline
C (WinForm) the current thread is not in a single threaded unit, so ActiveX controls cannot be instantiated
读libco保存恢复现场汇编代码
Learn about MySQL transaction isolation level
神经网络自我认知模型
CVPR 2022 best student paper: single image estimation object pose estimation in 3D space
中国银河证券开户安全吗 开户后多久能买股票
Matlab reference
Ant financial's sudden wealth has not yet begun, but the myth of zoom continues!
This 17-year-old hacker genius cracked the first generation iPhone!
Why is February 28 in the Gregorian calendar