Pat(Advanced Level)Practice--1028(List Sorting)

Pat1028 代码

题目描述:

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

Input

Each input file contains one test case. For each case, the first line contains two integers N (<=100000) 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

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

AC代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define MAX 100005

using namespace std;

typedef struct Student
{
	char ID[10];
	char name[10];
	int score;
}Stu;

bool cmp1(const Stu &s1,const Stu &s2)
{
	if(strcmp(s1.ID,s2.ID)<0)
		return true;
	else 
		return false;
}

bool cmp2(const Stu &s1,const Stu &s2)
{
	if(strcmp(s1.name,s2.name)<0)
		return true;
	else if(strcmp(s1.name,s2.name)==0&&strcmp(s1.ID,s2.ID)<0)
		return true;
	else
		return false;
}

bool cmp3(const Stu &s1,const Stu &s2)
{
	if(s1.score<s2.score)
		return true;
	else if(s1.score==s2.score&&strcmp(s1.ID,s2.ID)<0)
		return true;
	else 
		return false;
}

int main(int argc,char *argv[])
{
	int n,c;
	int i;
	Stu v[MAX];
	scanf("%d%d",&n,&c);
	for(i=0;i<n;i++)
		scanf("%s %s %d",v[i].ID,v[i].name,&v[i].score);
	if(c==1)
		sort(v,v+n,cmp1);
	else if(c==2)
		sort(v,v+n,cmp2);
	else
		sort(v,v+n,cmp3);
	for(i=0;i<n;i++)
		printf("%s %s %d\n",v[i].ID,v[i].name,v[i].score);
	return 0;
}

sort()排序的训练,没什么好说的,需要注意的一点是,如果用cin,cout输入输出则最后一个case超时。。。
在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、付费专栏及课程。

余额充值