当前位置:网站首页>删除数组中的某几个元素
删除数组中的某几个元素
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
- 企业数字化发展中的六个安全陋习,每一个都很危险!
- 2022新版PMP考试有哪些变化?
- Mongodb (quick start) (I)
- Accuracy of BigDecimal Division
- Knowledge points of MySQL (6)
- 论文阅读_医疗NLP模型_ EMBERT
- Which platform of outer disk gold is regular and safe, and how to distinguish it?
- Teamcenter 消息注册前操作或后操作
- Knowledge points of MySQL (7)
猜你喜欢

flask接口响应中的中文乱码(unicode)处理

CVPR 2022 best student paper: single image estimation object pose estimation in 3D space

提高應用程序性能的7個DevOps實踐

2022新版PMP考试有哪些变化?

Thesis reading_ Chinese NLP_ LTP
What are the precautions for MySQL group by

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

Knowledge points of MySQL (7)

Machine learning 01: Introduction
随机推荐
Thesis reading_ Chinese NLP_ LTP
c#图文混合,以二进制方式写入数据库
Design of electronic clock based on 51 single chip microcomputer
leetcode每日一练:旋转数组
7 pratiques devops pour améliorer la performance des applications
论文阅读_医疗NLP模型_ EMBERT
The comprehensive competitiveness of Huawei cloud native containers ranks first in China!
Cartoon: how to multiply large integers? (I) revised version
VBA驱动SAP GUI实现办公自动化(二):判断元素是否存在
EPM相关
漫画:如何实现大整数相乘?(上) 修订版
WebApp开发-Google官方教程
华为云云原生容器综合竞争力,中国第一!
Oracle recovery tools -- Oracle database recovery tool
Please tell me why some tables can find data by writing SQL, but they can't be found in the data map, and the table structure can't be found
SQL Server(2)
请问下为啥有的表写sql能查到数据,但在数据地图里查不到啊,查表结构也搜不到
Troubleshooting - about clip not found Visual Studio
如何保存训练好的神经网络模型(pytorch版本)
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声