1028 List Sorting (25 point(s)) - C语言 PAT 甲级

1028 List Sorting (25 point(s))

Excel can sort records according to any column. Now you are supposed to imitate this function.

Input Specification:

Each input file contains one test case. For each case, the first line contains two integers N (≤ 105) and C, where N is the number of records and C is the column that you are supposed to sort the records with. Then N lines follow, each contains a record of a student. A student’s record consists of his or her distinct ID (a 6-digit number), name (a string with no more than 8 characters without space), and grade (an integer between 0 and 100, inclusive).

Output Specification:

For each test case, output the sorting result in N lines. That is, if C = 1 then the records must be sorted in increasing order according to ID’s; if C = 2 then the records must be sorted in non-decreasing order according to names; and if C = 3 then the records must be sorted in non-decreasing order according to grades. If there are several students who have the same name or grade, they must be sorted according to their ID’s in increasing order.

Sample Input 1:

3 1
000007 James 85
000010 Amy 90
000001 Zoe 60

Sample Output 1:

000001 Zoe 60
000007 James 85
000010 Amy 90

Sample Input 2:

4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98

Sample Output 2:

000010 Amy 90
000002 James 98
000007 James 85
000001 Zoe 60

Sample Input 3:

4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90

Sample Output 3:

000001 Zoe 60
000007 James 85
000002 James 90
000010 Amy 90

题目大意:

输入 N 个学生信息,id、name、grade;

根据 C 的值排序,当 C 为 1,按第一列升序;当 C 为 2,按第二列不降序;当 C 为 3,按第三列不降序;第二、三列值相同时,按 id 升序;

设计思路:

按题目要求排序后,输出

编译器:C (gcc)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct stu {
	int id;
	char name[9];
	int grade;
};

int cmp1(const void *a, const void *b)
{
	struct stu *s1 = (struct stu*)a, *s2 = (struct stu*)b;
	return s1->id - s2->id;
}

int cmp2(const void *a, const void *b)
{
	struct stu *s1 = (struct stu*)a, *s2 = (struct stu*)b;
	int flag;
	flag = strcmp(s1->name, s2->name);
	if (flag)
		return flag;
	else
		return s1->id - s2->id;
}

int cmp3(const void *a, const void *b)
{
	struct stu *s1 = (struct stu*)a, *s2 = (struct stu*)b;
	int flag;
	flag = s1->grade - s2->grade;
	if (flag)
		return flag;
	else
		return s1->id - s2->id;
}

int main(v9id)
{
	int n, c;
	struct stu stus[100000] = {0};
	int i;

	scanf("%d %d", &n, &c);
	for (i = 0; i < n; i++)
		scanf("%d %s %d", &stus[i].id, stus[i].name, &stus[i].grade);

	if (c == 1)
		qsort(stus, n, sizeof(struct stu), cmp1);
	else if (c == 2)
		qsort(stus, n, sizeof(struct stu), cmp2);
	else
		qsort(stus, n, sizeof(struct stu), cmp3);

	for (i = 0; i < n; i++)
		printf("%06d %s %d\n", stus[i].id, stus[i].name, stus[i].grade);


	return 0;
}
在Unity中使用Spine插件时,设置SortingLayer可以帮助你控制多个Spine对象或者Spine对象与其他2D对象的渲染顺序。每个SortingLayer可以看作是一个独立的层级,可以对层级中的对象进行排序,这样就可以决定哪些对象在其他对象的前面或后面渲染。 设置SortingLayer通常有以下步骤: 1. 为Spine对象分配SortingLayer: 在Unity编辑器中选择Spine对象,然后在Inspector面板中找到“Sorting Layer”下拉菜单,从列表中选择一个已存在的或者新建一个SortingLayer名称。 2. 设置SortingOrder: 在“Sorting Layer”旁边有一个“Order in Layer”字段,这个字段决定了同一SortingLayer内的排序顺序。数值越大,对象在渲染时就越靠前。 3. 对于多个SortingLayer的情况,可以通过脚本动态修改SortingLayer和SortingOrder: 通过Spine对象的Renderer组件(例如SpriteRenderer),可以访问并修改sortingLayerName和sortingOrder属性。 ```csharp using UnityEngine; using UnityEngine.UI; public class SetSortingLayer : MonoBehaviour { void Start() { // 获取Renderer组件 Renderer rend = gameObject.GetComponent<Renderer>(); if (rend != null) { // 设置SortingLayer名称 rend.sortingLayerName = "YourSortingLayerName"; // 设置SortingOrder值 rend.sortingOrder = 1; } } } ``` 请确保你的Spine对象拥有Renderer组件,否则上述代码中的`rend`将会是null。常见的Renderer组件包括SpriteRenderer、MeshRenderer等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值