PTA---C语言:多数组排序

程序展示了如何使用C语言对三个整数数组进行合并并按降序排列。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3个整数数组进行整体排序,根据输入的三个数组的元素,输出排序后的结果(从大到小)

输入格式:

第1个数组的长度

第1个数组的各个元素

第2个数组的长度

第2个数组的各个元素

第3个数组的长度

第3个数组的各个元素

输出格式:

所有数组的整体排序

输入样例:

在这里给出一组输入。例如:

3 
79 80 61
3
88 66 77
2
23 90

输出样例:

在这里给出相应的输出。例如:

90 88 80 79 77 66 61 23

#include<stdio.h>
int main()
{
	int n1,n2,n3,cnt=0;   //n1 is first group,n2...,n3...cnt is used as count(计数)
    int i,j;
    int str[1000];   //build a array(数组)
    int num;   //num is element(元素)
//first group culculate(计算)
    scanf("%d",&n1);
   	for(i=0;i<n1;i++)
    {
        scanf("%d",&num);
        str[i]=num;
    }
    cnt=n1;   //count(计数)
//second group culculate
    scanf("%d",&n2);
   	for(i=cnt;i<n2+cnt;i++)
    {
        scanf("%d",&num);
        str[i]=num;
    }
    cnt=cnt+n2;
//third group culculate
    scanf("%d",&n3);
   	for(i=cnt;i<n3+cnt;i++)
    {
        scanf("%d",&num);
        str[i]=num;
    }
    cnt=cnt+n3;
//sort(排序)
    for(j=1;j<=cnt;j++)
    {
	 	for(i=0;i<=cnt-j;i++)
	    {
	        if(str[i]<str[i+1])
	        {
	            int t=str[i];
	            str[i]=str[i+1];
	            str[i+1]=t;
	        }
	    }
    }
//output(输出)------is important advise:keep to mind
    printf("%d",str[0]);
    for(i=1;i<cnt;i++)
    {
        printf(" %d",str[i]);
    }
//tail is nobreakspace(空格)
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值