当前位置:网站首页>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;
}
边栏推荐
- Install nccl \ mpirun \ horovod \ NVIDIA tensorflow (3090ti)
- CLM陆面过程模式
- Seata submits at details in two stages
- Black eat black? The man cracked the loopholes in the gambling website and "collected wool" for more than 100000 yuan per month
- Shell process control (emphasis), if judgment, case statement, let usage, for ((initial value; loop control condition; variable change)) and for variable in value 1 value 2 value 3..., while loop
- no networks found in /etc/cni/net.d
- C语言实现发牌功能基本方法
- 手把手教你用代码实现SSO单点登录
- Full analysis of domain name resolution process means better text understanding
- Computable general equilibrium (CGE) model practice technology in resource environment under the goal of "double carbon"
猜你喜欢

MySQL basic learning

MODFLOW flex, GMS, FEFLOW, hydraus practical application

517. 超级洗衣机

真正的科学减肥

Ansible中常用的模块

pillow的原因ImportError: cannot import name ‘PILLOW_VERSION‘ from ‘PIL‘,如何安装pillow<7.0.0

Full analysis of domain name resolution process means better text understanding

使用Ansible中的playbook

An online accident, I suddenly realized the essence of asynchrony

Shell的read 读取控制台输入、read的使用
随机推荐
JVM Lecture 6: how to solve the frequent FGC in online environment?
C语言详解系列——函数的认识(3)形参,实参,嵌套调用和链式访问
Distance between bus stops: simple simulation problem
When AQS wakes up the thread, I understand why it traverses from the back to the front
Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
Unity scene jump script
I talked with the interviewer about MySQL optimization in five dimensions
JVM Lecture 2: class loading mechanism
FPGA刷题——序列检测
kubernetes install completed
CMD操作命令
ALV program collection
SAP report development steps
Compilation method of flood control evaluation report and flood modeling under the new guidelines
Nacos registry
手把手教你用代码实现SSO单点登录
Mysql优化
Redis expiration deletion strategy and memory obsolescence strategy
DOM event flow event bubble event capture event delegate
MySQL master-slave synchronization and master-slave synchronization delay solution