当前位置:网站首页>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
CCPointsArray , It's stored here n Structures - Given another structure
PointArray - 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
边栏推荐
- What are the requirements for PMP certification? How much is it?
- IDEA 项目启动报错 Shorten the command line via JAR manifest or via a classpath file and rerun.
- Mysql5.6 parsing JSON strings (supporting complex nested formats)
- SQL Server(2)
- Teamcenter 消息注册前操作或後操作
- Oracle recovery tools -- Oracle database recovery tool
- Is it safe for China Galaxy Securities to open an account? How long can I buy stocks after opening an account
- 基于YOLOv3的口罩佩戴检测
- Tita performance treasure: how to prepare for the mid year examination?
- The comprehensive competitiveness of Huawei cloud native containers ranks first in China!
猜你喜欢
随机推荐
PMP认证需具备哪些条件啊?费用多少啊?
每日一练:关于日期的一系列
Ordinary programmers look at the code, and top programmers look at the trend
Abnormal recovery of virtual machine Oracle -- Xi Fenfei
查看自己电脑连接过的WiFi密码
Cmake tutorial Step4 (installation and testing)
Kafaka技术第一课
Cartoon: how to multiply large integers? (I) revised version
Ant financial's sudden wealth has not yet begun, but the myth of zoom continues!
leetcode每日一题:字符串中的第一个唯一字符
Zabbix
Disabling and enabling inspections pycharm
統計php程序運行時間及設置PHP最長運行時間
力扣解法汇总1200-最小绝对差
Server configuration jupyter environment
SQL Server(2)
北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
What are the requirements for PMP certification? How much is it?
Interpretation: how to deal with the current security problems faced by the Internet of things?
Simple query cost estimation









