当前位置:网站首页>TZC 1283: simple sort - Comparative sort
TZC 1283: simple sort - Comparative sort
2022-07-26 05:17:00 【Orange teacher】
We use TZC 1283 As an example, briefly explain the sorting ( Including ten classic sorting algorithms ) Of python Implementation method and C Implementation method . Comparative sorting is the simplest method , The core essence is to press and hold the first one and compare it with all the following , Then press and hold the second one for the second time and compare it with all the others in the back .
Original link :1283: Simple order

python The code is as follows :
# Compare sort
def cmp_sort(lst):
length = len(lst)
for a in range(0, length - 1):
for b in range(a + 1, length):
if lst[a] > lst[b]:
t = lst[a]
lst[a] = lst[b]
lst[b] = t
T = int(input())
for i in range(T):
s = input().split()
lt = [int(x) for x in s]
lt1 = lt[::-1]
lt1.pop()
n = len(lt1)
cmp_sort(lt1)
for j in range(n):
if j != n - 1:
print(lt1[j], end=' ')
else:
print(lt1[j])

C The language code is as follows :
#include <stdio.h>
void cmpsort(int x[],int n)
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(x[i]>x[j])
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
}
}
int main()
{
int m,n,i,j,a[1000]={0};
scanf("%d",&m);
while(m--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
cmpsort(a,n);
for(i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]);
}
return 0;
}
边栏推荐
- 嵌入式开发小记,实用小知识分享
- CLM land surface process model
- OD-Paper【2】:Fast R-CNN
- Shell的read 读取控制台输入、read的使用
- Seata submits at details in two stages
- C language function
- CMD operation command
- Use flutter to adjust a color filter for the picture of my little sister
- Flex layout principle and common parent elements
- DOM event flow event bubble event capture event delegate
猜你喜欢

C语言-指针进阶

Ansible中常用的模块

DOM事件流 事件冒泡-事件捕获-事件委托

MySQL optimization
![Bash shortcut key to improve command line efficiency [Full Version]](/img/ec/f0dd2fbfac6853ae60d7cf52d8f3e1.png)
Bash shortcut key to improve command line efficiency [Full Version]
![Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning](/img/87/9f8353c5c9c700eaa63f66697aa44a.png)
Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning

开发转测试:从零开始的6年自动化之路

ALV report flow diagram
C语言详解系列——函数的认识(3)形参,实参,嵌套调用和链式访问

Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
随机推荐
C language function
How to reproduce the official course of yolov5 gracefully (II) -- Mark and train your own data set
TZC 1283: simple sort - select sort
C语言-指针进阶
If MySQL calculates the current month change / current month increase / year-on-year change / year-on-year increase?
Nacos 介绍和部署
攻防世界--easy_web
TZC 1283: simple sort Bubble Sort
C语言详解系列——函数的认识(4)函数的声明与定义,简单练习题
Distance between bus stops: simple simulation problem
No background, no education? Is it really hopeless for specialist testers to enter Internet factories?
嵌入式分享合集20
ALV程序收集
Why is the value represented by a negative number greater than an integer by 1?
Embedded sharing collection 21
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
[pytorch] install torch 1.8.1 and check whether torch version and GPU are available
OD-Paper【2】:Fast R-CNN
Redis expiration deletion strategy and memory obsolescence strategy
SSTI-payload和各种绕过方法