当前位置:网站首页>The way to conquer C language
The way to conquer C language
2022-04-23 02:42:00 【^O ^ play programming】
Catalog
Preface
Today, I'd like to share with you some questions of niuke.com
subject
1 Delete the specified number from the sequence

Original idea : Is to find the number to replace in the sequence first , Delete this number , But I soon found myself unable to delete this number .( Some friends who know how to delete can tell me oh !).
Their thinking :1 Exclude the number of deletions from the sequence .
2 Before moving the number after this sequence forward .
3 Print this new sequence .
Code :
#include<stdio.h>
int main()
{
int n = 0;
scanf("%d",&n);
int arr[50]={0};
int i = 0;
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
// Enter the number of deletions
int del = 0;
scanf("%d",&del);
int j = 0;
for(i=0;i<n;i++)
{
if(arr[i]!=del)
{
arr[j++]=arr[i];
}
}
// Print
for(i=0;i<j;i++)
{
printf("%d ",arr[i]);
}
return 0;
}
2 Integer de duplication in sequence

Their thinking :1 Find the same elements
2 If the number of elements is the same , Move the subsequent elements forward
Code :
#include<stdio.h>
int main()
{
int n = 0;
scanf("%d", &n);
// data input
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++)
{
// Find the same element first
// If the same , Move the subsequent elements previously
if (arr[i] == arr[j])
{
int m = 0;
for (m = j;m < n - 1;m++)
{
arr[m] = arr[m + 1];
}
n--;// Indicates that an identical number has been removed
j--;// Continue to judge whether the next one is multiplicative
}
}
}
for (i = 0;i < n;i++)
{
printf("%d ", arr[i]);
}
return 0;
}
3 Ordered sequence merging
Their thinking :1 Create three arrays arr1 and arr2 And arr3 Let the subscripts be i and j And k( The initial values are 0).
2 Give Way arr1[i] and arr2[j] Compare , Let a smaller number be deposited in arr3 Zhongzai Jean i++ perhaps j++, Then continue to compare .
3 When arr1 perhaps arr2 After all the elements in are saved, continue to store the unfinished array in arr3 in .
Code :
#include<stdio.h>
int main()
{
int n = 0;
int m = 0;
scanf("%d %d", &n, &m);
int arr1[1000] = { 0 };
int arr2[1000] = { 0 };
int arr3[2000] = { 0 };
// data input
int i = 0;
for (i = 0;i < n;i++)
{
scanf("%d", &arr1[i]);
}
for (i = 0;i < m;i++)
{
scanf("%d", &arr2[i]);
}
// Handle
int j = 0;
int k = 0;
i = 0;
while (i < n && j < m)
{
// Put a smaller number into the merged array
if (arr1[i] < arr2[j])
{
arr3[k++] = arr1[i++];
}
else
{
arr3[k++] = arr2[j++];
}
}
// When arr1 The array elements are saved first
// take arr2 Put the remaining number in arr3 in
if (i == n)
{
for (;j < m;j++)
{
arr3[k++] = arr2[j];
}
}
else
{
for (;i < n;i++)
{
arr3[k++] = arr1[i];
}
}
// Print arr3
for (i = 0;i < k;i++)
{
printf("%d ", arr3[i]);
}
return 0;
}
Conclusion
I'll share it with you today , I hope my friends can give me more advice , Come on, everybody , Progress together !

版权声明
本文为[^O ^ play programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220748162451.html
边栏推荐
- 16、 Anomaly detection
- 智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售
- ROP Emporium x86_ 64 7 ~ 8 questions
- win查看端口占用 命令行
- 谷雨
- [XJTU計算機網絡安全與管理]第二講 密碼技術
- JZ22 鏈錶中倒數最後k個結點
- How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year
- 程序设计天梯赛 L1-49 天梯赛分配座位(模拟),布响丸辣
- OCR识别PDF文件
猜你喜欢

leangoo脑图-共享式多人协作思维导图工具分享

Fast and robust multi person 3D pose estimation from multiple views

Machine learning (Zhou Zhihua) Chapter 14 probability graph model

一、序列模型-sequence model

How to prevent leakage of operation and maintenance data

工业互联网+危化安全生产综合管理平台怎样建

定了,今日起,本号粉丝可免费参与网易数据分析培训营!

How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year

Real math problems in 1958 college entrance examination

Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl
随机推荐
Push data from onenet cloud platform to database
本地远程访问云服务器的jupyter
想用Mac学习sql,主要给自己个充足理由买Mac听听意见
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
[untitled]
Fashion MNIST dataset classification training
JDBC JDBC
C language 171 Number of recent palindromes
Rhcsa day 3 operation
Preliminary understanding of stack and queue
Flink stream processing engine system learning (I)
mysql function函数语法
How big the program development of single chip microcomputer project can be, it represents your level of knocking code
Probabilistic model of machine learning
Flink stream processing engine system learning (II)
Windows MySQL 8 zip installation
Talk about current limiting
Rhcsa day 4 operation
Class initialization and instance initialization interview questions
A domestic image segmentation project is heavy and open source!