当前位置:网站首页>TZC 1283: simple sorting - function method
TZC 1283: simple sorting - function method
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 . First, the function method ,python Can be used in sort function ,C Language can be used qsort Function implementation .
Original link :1283: Simple order

Python It's easier to write , The code is as follows :
T = int(input())
for i in range(T):
s = input().split()
lt = [int(x) for x in s]
lt1 = lt[::-1]
lt1.pop()
lt1.sort()
n = len(lt1)
for j in range(n):
if j != n-1:
print(lt1[j], end=' ')
else:
print(lt1[j])
C Language is not like C++ or python, No, sort function , Only qsort function , It's not so convenient to use , You need to customize the comparison function cmp.
#include<stdio.h>
int cmp(const void *a ,const void *b)
{
return *(int *)a - *(int *)b;
}
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]);
qsort(a,n,sizeof(a[0]),cmp); // qsort function
for(i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]);
}
return 0;
}
边栏推荐
- A material of machine learning
- OD-Paper【1】:Rich feature hierarchies for accurate object detection and semantic segmentation
- Shell的read 读取控制台输入、read的使用
- Annotation @autowired how to assemble automatically
- Unity scene jump script
- C语言详解系列——函数的认识(3)形参,实参,嵌套调用和链式访问
- Common modules in ansible
- Princeton calculus reader 02 Chapter 1 -- composition of functions, odd and even functions, function images
- Redis expiration deletion strategy and memory obsolescence strategy
- How many holes have you stepped on in BigDecimal?
猜你喜欢

unity场景跳转脚本

mysql如果计算本月变动/本月增幅/同比变动/同比增幅?

Uniapp applet framework - a set of code, multi segment coverage

Go-Excelize API源码阅读(六)—— DeleteSheet(sheet string)

新导则下的防洪评价报告编制方法及洪水建模

ALV程序收集
C语言详解系列——函数的认识(4)函数的声明与定义,简单练习题

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

嵌入式开发小记,实用小知识分享
![[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
随机推荐
ALV入门
Test of countlaunch demo
怎么办理聚合收款码
Distance between bus stops: simple simulation problem
Common modules in ansible
推荐12个免费查找文献的学术网站,建议点赞、收藏!
C语言力扣第42题之接雨水。四种方法——暴力、动态规划、栈、双指针
Nacos introduction and deployment
nacos注册中心
CLM land surface process model
测试必备工具之Fiddler,你真的了解吗?
Go-Excelize API源码阅读(六)—— DeleteSheet(sheet string)
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
npm操作指令
MySQL基础学习
Compilation method of flood control evaluation report and flood modeling under the new guidelines
[Luogu] p1383 advanced typewriter
新导则下的防洪评价报告编制方法及洪水建模
Please elaborate on the implementation principle of synchronized and related locks
Map making of environmental impact assessment based on remote sensing interpretation and GIS technology