当前位置:网站首页>删除数组中的某几个元素
删除数组中的某几个元素
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
边栏推荐
- 漫画:有趣的【海盗】问题
- Kafaka technology lesson 1
- 十个顶级自动化和编排工具
- Machine learning 01: Introduction
- Mongodb (quick start) (I)
- 如何修改mysql字段为自增长字段
- Interpretation: how to deal with the current security problems faced by the Internet of things?
- In depth understanding of redis memory obsolescence strategy
- 外盘黄金哪个平台正规安全,怎么辨别?
- Summary of optimization scheme for implementing delay queue based on redis
猜你喜欢

leetcode每日一题:字符串中的第一个唯一字符
Database design in multi tenant mode

Oracle recovery tools -- Oracle database recovery tool

Machine learning 01: Introduction

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

Vulnerability recurrence - 48. Command injection in airflow DAG (cve-2020-11978)

查看自己电脑连接过的WiFi密码

ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
Complete solution instance of Oracle shrink table space

统计php程序运行时间及设置PHP最长运行时间
随机推荐
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
漫画:寻找无序数组的第k大元素(修订版)
提高應用程序性能的7個DevOps實踐
世界上最难的5种编程语言
漫画:如何实现大整数相乘?(上) 修订版
How to save the trained neural network model (pytorch version)
神经网络自我认知模型
每日一练:关于日期的一系列
Database design in multi tenant mode
企业数字化发展中的六个安全陋习,每一个都很危险!
Cartoon: interesting [pirate] question
Interpretation: how to deal with the current security problems faced by the Internet of things?
Which platform of outer disk gold is regular and safe, and how to distinguish it?
网络威胁分析师应该具备的十种能力
mysql5.6解析JSON字符串方式(支持复杂的嵌套格式)
漫画:有趣的【海盗】问题
Why is all (()) true and any (()) false?
ITK Example
LeetCode每日一题:合并两个有序数组
Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition