当前位置:网站首页>C language double pointer -- classic question type
C language double pointer -- classic question type
2022-07-06 08:32:00 【Finally - null】
Make a little progress every day , Persistence makes a big difference !!!

1. Deletes the specified number from the sequence
Link to Niuke :
describe
There is a sequence of integers ( There may be duplicate integers ), Now delete a specified integer , Output the sequence after deleting the specified number , There is no change in the front and back positions of the undeleted numbers in the sequence .
Data range : Both the length of the sequence and the values in the sequence satisfy 1≤n≤50
Input description :
Enter an integer in the first line (0≤N≤50).
Second line input N It's an integer , Enter space delimited N It's an integer .
On the third line, enter an integer you want to delete .
Output description :
Output as a line , Delete the sequence after the specified number .
Example 1
Input :
6
1 2 3 4 5 9
4
Output :1 2 3 5 9Example 2
Input :
5
1 2 3 4 6
5
Output :1 2 3 4 6
Ideas :
Define two variables , Are subscripted from the array 0 The position begins ,i Variables traverse the entire array ,j Variables are used to store elements that are not deleted , When i After finding the deleted element i Continue to visit backwards ,j No more , When it is not the element to be deleted , Mark the subscript as i The elements of are stored in j Subscript , then j Continue to add .
#include<stdio.h> int main() { int n = 0; int arr[50] = { 0 }; scanf("%d", &n); int i = 0; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } int del = 0; int j = 0; scanf("%d", &del); for (i = 0; i < n; i++) { if (arr[i] != del) { arr[j++] = arr[i]; } } for (i = 0; i < j; i++) { printf("%d ", arr[i]); } return 0; }
2. Remove duplicates from the sequence
Link to Niuke :
describe
Input n A sequence of integers , This sequence is required to be de duplicated . So called de duplication , It refers to every repeated integer in this sequence , Keep only the position where the number first appears , Delete the rest of the position .
Input description :
The input contains two lines , The first line contains a positive integer n(1 ≤ n ≤ 1000), Represents the number of numbers in the second row sequence ; The second line contains n It's an integer ( Range 1~5000), Separate... With spaces .
Output description :
Output as a line , Output the number after de duplication in the order of input , Separate... With spaces .
Example 1
Input :
5
10 12 93 12 75
Output :
10 12 93 75
Ideas :
#include<stdio.h> int main() { int n = 0; scanf("%d", &n); int arr[1000] = { 0 }; int i = 0; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (i = 0; i < n; i++) { int j = 0; for (j = i + 1; j < n; j++) { if (arr[i] == arr[j]) { int k = 0; for (k = j; k < n - 1; k++) { arr[k] = arr[k + 1]; } n--; j--; } } } for (i = 0; i < n; i++) { printf("%d ", arr[i]); } return 0; }
3. Merging of ordered sequences :
Link to Niuke :
describe
Enter two ascending sequences , Combine the two sequences into an ordered sequence and output .
Data range :1≤n,m≤1000 , The values in the sequence satisfy :0≤val≤30000
Input description :
The input contains three lines ,
The first line contains two positive integers n, m, Separate... With spaces .n Represents the number of numbers in the first ascending sequence of the second line ,m Represents the number of numbers in the second ascending sequence in the third row .
The second line contains n It's an integer , Separate... With spaces .
The third line contains m It's an integer , Separate... With spaces .Output description :
Output as a line , The output length is n+m Ascending sequence of , The length is n The ascending sequence and length of m Rearrange and merge the elements in the ascending sequence of .
Example 1
Input :
5 6
1 3 7 9 22
2 8 10 17 33 44
Output :1 2 3 7 8 9 10 17 22 33 44
Ideas :
#include<stdio.h> int main() { int arr1[1000] = { 0 }; int arr2[1000] = { 0 }; int arr3[2000] = { 0 }; int n = 0; int m = 0; scanf("%d%d", &n, &m); int i = 0; for (i = 0; i < n; i++) { scanf("%d", &arr1[i]); } for (i = 0; i < m; i++) { scanf("%d", &arr2[i]); } 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 < n + m; i++) { printf("%d ", arr3[i]); } return 0; }
边栏推荐
- JVM performance tuning and practical basic theory - Part 1
- Introduction to number theory (greatest common divisor, prime sieve, inverse element)
- What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
- The mysqlbinlog command uses
- JVM performance tuning and practical basic theory - Part 1
- Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
- LDAP應用篇(4)Jenkins接入
- Is it safe to open an account in Zheshang futures?
- 2. File operation - write
- [research materials] 2022 China yuancosmos white paper - Download attached
猜你喜欢

IOT -- interpreting the four tier architecture of the Internet of things

Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)

All the ArrayList knowledge you want to know is here

egg. JS getting started navigation: installation, use and learning

个人电脑好用必备软件(使用过)

Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation

【MySQL】日志

Deep learning: derivation of shallow neural networks and deep neural networks

JVM performance tuning and practical basic theory - Part 1

查看局域网中电脑设备
随机推荐
IoT -- 解读物联网四层架构
ESP系列引脚说明图汇总
sublime text中conda环境中plt.show无法弹出显示图片的问题
Image fusion -- challenges, opportunities and Countermeasures
游戏解包的危害及资源加密的重要性
Cisp-pte practice explanation
【MySQL】数据库的存储过程与存储函数通关教程(完整版)
化不掉的钟薛高,逃不出网红产品的生命周期
Migrate data from a tidb cluster to another tidb cluster
Function coritization
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Analysis of pointer and array written test questions
电脑F1-F12用途
JVM performance tuning and practical basic theory - Part 1
ROS编译 调用第三方动态库(xxx.so)
[2022 广东省赛M] 拉格朗日插值 (多元函数极值 分治NTT)
个人电脑好用必备软件(使用过)
egg. JS directory structure
Let the bullets fly for a while
Introduction to number theory (greatest common divisor, prime sieve, inverse element)
https://www.nowcoder.com/practice/7bbcdd2177a445a9b66da79512b32dd7?tpId=107&&tqId=33379&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking

