当前位置:网站首页>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;
}
边栏推荐
- Reason for pilot importerror: cannot import name 'pilot_ Version 'from' PIL ', how to install pilot < 7.0.0
- 提高shuffle操作中的reduce并行度
- YOLOv5执行全过程----目录
- Earth system model (cesm) practical technology
- I talked with the interviewer about MySQL optimization in five dimensions
- C语言力扣第42题之接雨水。四种方法——暴力、动态规划、栈、双指针
- ALV报表流程图解
- SQL注入
- 攻防世界--easy_web
- Mathematical modeling and optimization analysis based on general optimization software gams
猜你喜欢

security权限管理详解
![[pytorch] install torch 1.8.1 and check whether torch version and GPU are available](/img/97/078c72729a29675939a84895b5ab86.png)
[pytorch] install torch 1.8.1 and check whether torch version and GPU are available

Recommended reading: how can testers get familiar with new businesses quickly?

Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环

黑吃黑?男子破解赌博网站漏洞,每月“薅羊毛”10多万元

Teach you how to use code to realize SSO single sign on

LeetCode链表问题——206.反转链表(一题一文学会链表)

C language function

C language - Advanced pointer

Week 6 Learning Representation: Word Embedding (symbolic →numeric)
随机推荐
Getting started with ALV
Embedded sharing collection 21
Map making of environmental impact assessment based on remote sensing interpretation and GIS technology
测试用例评审如何开展
Embedded development notes, practical knowledge sharing
一次线上事故,我顿悟了异步的精髓
安装NCCL\mpirun\horovod\nvidia-tensorflow(3090Ti)
MySQL基础学习
FPGA刷题——序列检测
Leetcode linked list problem - 203. remove the linked list elements (learn the linked list by one question and one article)
Date and time function of MySQL function summary
Mysql优化
How many holes have you stepped on in BigDecimal?
If MySQL calculates the current month change / current month increase / year-on-year change / year-on-year increase?
Annotation @autowired how to assemble automatically
Application of remote sensing, GIS and GPS technology in hydrology, meteorology, disasters, ecology, environment and health
Excel VBA: realize automatic drop-down filling formula to the last line
Flex layout principle and common parent elements
Common modules in ansible
怎么办理聚合收款码