当前位置:网站首页>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; }
边栏推荐
- Longest palindrome substring (dynamic programming)
- Is it necessary to renew the PMP certificate?
- SQL injection - secondary injection and multi statement injection
- 创始人负债10亿,开课吧即将“下课”?
- [optimal web page width and its implementation] [recommended collection "
- 1.AVL树:左右旋-bite
- ssm框架的简单案例
- DBSync新增对MongoDB、ES的支持
- LabVIEW is opening a new reference, indicating that the memory is full
- 高压漏电继电器BLD-20
猜你喜欢
Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
MySQL数据库学习(8) -- mysql 内容补充
SQL injection - secondary injection and multi statement injection
Harmonyos fourth training
高压漏电继电器BLD-20
论文阅读【MM21 Pre-training for Video Understanding Challenge:Video Captioning with Pretraining Techniqu】
JHOK-ZBL1漏电继电器
张平安:加快云上数字创新,共建产业智慧生态
QT simple layout box model with spring
K6EL-100漏电继电器
随机推荐
照片选择器CollectionView
Safe landing practice of software supply chain under salesforce containerized ISV scenario
If you want to choose some departments to give priority to OKR, how should you choose pilot departments?
最长不下降子序列(LIS)(动态规划)
AOSP ~binder communication principle (I) - Overview
2039: [Bluebridge cup 2022 preliminaries] Li Bai's enhanced version (dynamic planning)
Wonderful express | Tencent cloud database June issue
Array initialization of local variables
【oracle】简单的日期时间的格式化与排序问题
Complete code of C language neural network and its meaning
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
JVM (19) -- bytecode and class loading (4) -- talk about class loader again
Let f (x) = Σ x^n/n^2, prove that f (x) + F (1-x) + lnxln (1-x) = Σ 1/n^2
Aidl and service
Tencent cloud database public cloud market ranks top 2!
Timer创建定时器
DJ-ZBS2漏电继电器
The founder has a debt of 1billion. Let's start the class. Is it about to "end the class"?
JVM(二十) -- 性能监控与调优(一) -- 概述
Vector and class copy constructors