当前位置:网站首页>删除数组中的某几个元素
删除数组中的某几个元素
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
边栏推荐
- Force deduction solution summary 729- my schedule I
- Read the history of it development in one breath
- 华为云云原生容器综合竞争力,中国第一!
- Why is all (()) true and any (()) false?
- Cmake tutorial step6 (add custom commands and generate files)
- 北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
- Ordinary programmers look at the code, and top programmers look at the trend
- How to save the trained neural network model (pytorch version)
- Flow characteristics of kitchen knife, ant sword, ice scorpion and Godzilla
- 如何保存训练好的神经网络模型(pytorch版本)
猜你喜欢

哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?
Database design in multi tenant mode

Kafaka技术第一课

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

论文阅读_医疗NLP模型_ EMBERT

Short the command line via jar manifest or via a classpath file and rerun

统计php程序运行时间及设置PHP最长运行时间

Machine learning 02: model evaluation
Tips for extracting JSON fields from MySQL

Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions
随机推荐
Sentinel flow guard
十个顶级自动化和编排工具
How to save the trained neural network model (pytorch version)
SQL Server(2)
2022新版PMP考试有哪些变化?
Cartoon: how to multiply large integers? (next)
数据访问 - EntityFramework集成
Knowing that his daughter was molested, the 35 year old man beat the other party to minor injury level 2, and the court decided not to sue
Disabling and enabling inspections pycharm
Matlab reference
Is it safe to open an account online? What is the general interest rate of securities financing?
Oracle recovery tools -- Oracle database recovery tool
求解为啥all(())是True, 而any(())是FALSE?
Vulnerability recurrence - 48. Command injection in airflow DAG (cve-2020-11978)
Complete solution instance of Oracle shrink table space
华为云云原生容器综合竞争力,中国第一!
Design of electronic clock based on 51 single chip microcomputer
Ant financial's sudden wealth has not yet begun, but the myth of zoom continues!
哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?
ITK Example