当前位置:网站首页>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;
}
边栏推荐
- Week 6 Learning Representation: Word Embedding (symbolic →numeric)
- Ansible tutorial
- 第二讲 初识SLAM
- Computable general equilibrium (CGE) model practice technology in resource environment under the goal of "double carbon"
- If MySQL calculates the current month change / current month increase / year-on-year change / year-on-year increase?
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- Nacos registry
- Practical technology of SWAT Model in simulation of hydrology, water resources and non-point source pollution
- C语言函数
- 【Leetcode】493. Reverse Pairs
猜你喜欢
![[acwing] 1268. Simple questions](/img/f3/7eeae566dd74d77cf6f8b4640e4f29.png)
[acwing] 1268. Simple questions

How many holes have you stepped on in BigDecimal?

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

JVM Lecture 5: how to deal with peak push of vertical and horizontal data

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

【pytorch】torch1.8.1安装、查看torch版本、GPU是否可用

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

Nacos registry

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

测试必备工具之Fiddler,你真的了解吗?
随机推荐
【pytorch】torch1.8.1安装、查看torch版本、GPU是否可用
提高shuffle操作中的reduce并行度
Webassembly 01 basic information
Black eat black? The man cracked the loopholes in the gambling website and "collected wool" for more than 100000 yuan per month
Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
Common modules in ansible
JVM Lecture 6: how to solve the frequent FGC in online environment?
没背景、没学历?专科测试员进入互联网大厂是不是真的没希望?
Getting started with ALV
Getaverse,走向Web3的远方桥梁
手把手教你用代码实现SSO单点登录
ALV入门
Basic methods of realizing licensing function in C language
基于通用优化软件GAMS的数学建模和优化分析
Full analysis of domain name resolution process means better text understanding
no networks found in /etc/cni/net.d
[Luogu] p1383 advanced typewriter
提升命令行效率的 Bash 快捷键 [完整版]
[acwing] 2983. Toys