当前位置:网站首页>Preliminary practice of niuke.com (9)
Preliminary practice of niuke.com (9)
2022-07-07 05:31:00 【Deer nine pills】
Catalog
1. Deletes the specified number from the sequence
2. Integer de duplication in sequence
1. Deletes the specified number from the sequence
#include<stdio.h> int main() { int n = 0; int arr[50] = { 0 }; int delete = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } scanf("%d", &delete); int i = 0; int j = 0; for (i = 0, j = 0; i < n; i++) {//i The role of : Traversal array //j The role of : Record the subscript where the data is stored if (arr[i] != delete) { arr[j++] = arr[i]; } // At this time j The data stored in is the number of elements left after deleting elements } for (int i = 0; i < j; i++) { printf("%d ", arr[i]); } return 0; }
2. Integer de duplication in sequence
Method 1:
( Compare with the previous elements )
#include<stdio.h> int main() { int n = 0; int arr[1000] = { 0 }; scanf("%d", &n); int i = 0; int j = 0; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } // duplicate removal j = 1; for (i = 1; i < n; i++)// Start traversing from the second { int flag = 0; for (int k = 0; k < i; k++) { if (arr[k] == arr[i]) { flag = 1; } } if (flag != 1) { arr[j++] = arr[i]; }// The method here is similar to that of the above question } for (int i = 0; i < j; i++) { printf("%d ", arr[i]); } return 0; }
Method 2:
#include<stdio.h> int main() { int n = 0; int arr[1000] = { 0 }; scanf("%d", &n); int i = 0; int j = 0; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } // duplicate removal for (i = 0; i < n; i++) { // Judge arr[i] Has it ever appeared in the back int j = 0; for (j = i + 1; j < n; j++) { if (arr[i] == arr[j]) { // duplicate removal , That is, the following elements cover the front int k = 0; for (k = j; k < n - 1; k++) { arr[k] = arr[k + 1]; } n--; j--;// Prevent the covering up from still being the same as the front arr[i] Elements repeat } } } for (int i = 0; i < n; i++) { printf("%d ", arr[i]); } return 0; }
3. Ordered sequence merging
#include<stdio.h> #include<malloc.h> int main() { int n = 0; int m = 0; int all = m+n; int i = 0; // Input n and m scanf("%d %d",&n,&m); int *arr1 = (int *)malloc(sizeof(int)*n); int *arr2 = (int *)malloc(sizeof(int)*m); int *arr3 = (int *)malloc(sizeof(int)*(m+n)); // Enter two ordered arrays for(int i = 0;i<n;i++) { scanf("%d",&arr1[i]); } for(int i = 0;i<m;i++) { scanf("%d",&arr2[i]); } // Merge array i = 0; int j = 0; int k = 0; while(i<n&&j<m) { if(arr1[i]<arr2[j]) { arr3[k++] = arr1[i++]; } else { arr3[k++] = arr2[j++]; } } if(i==n) { for(;j<m;j++) { arr3[k++] = arr2[j]; } } else { for(;i<n;i++) { arr3[k++] = arr1[i]; } } for( i =0;i<k;i++) { printf("%d ",arr3[i]); } return 0; }
边栏推荐
- Mysql database learning (8) -- MySQL content supplement
- 利用OPNET进行网络指定源组播(SSM)仿真的设计、配置及注意点
- 痛心啊 收到教训了
- Dj-zbs2 leakage relay
- 利用OPNET进行网络任意源组播(ASM)仿真的设计、配置及注意点
- Mysql database learning (7) -- a brief introduction to pymysql
- Zero sequence aperture of leakage relay jolx-gs62 Φ one hundred
- 《2》 Label
- 创始人负债10亿,开课吧即将“下课”?
- DFS,BFS以及图的遍历搜索
猜你喜欢
K6EL-100漏电继电器
Autowired注解用于List时的现象解析
Intelligent annotation scheme of entity recognition based on hugging Face Pre training model: generate doccano request JSON format
《4》 Form
sql优化常用技巧及理解
Life experience of an update statement
Is PMP really useful?
Photo selector collectionview
JHOK-ZBG2漏电继电器
Make web content editable
随机推荐
Harmonyos fourth training
Creation and use of thread pool
磁盘监控相关命令
一条 update 语句的生命经历
“多模态”概念
CentOS 7.9 installing Oracle 21C Adventures
《2》 Label
QSlider of QT control style series (I)
SQL injection - secondary injection and multi statement injection
Safe landing practice of software supply chain under salesforce containerized ISV scenario
JHOK-ZBG2漏电继电器
Full link voltage test: the dispute between shadow database and shadow table
漏电继电器JOLX-GS62零序孔径Φ100
JHOK-ZBL1漏电继电器
删除文件时提示‘源文件名长度大于系统支持的长度’无法删除解决办法
Most commonly used high number formula
High voltage leakage relay bld-20
ScheduledExecutorService定时器
Timer create timer
TabLayout修改自定义的Tab标题不生效问题