小鑫の日常系列故事(十)——排名次-2741

原题链接

Java语言没有c/c++中的struct,没办法还是得用Java来写,只能从其他的地方借鉴了,其中,类是一个不错的选择,虽然还不会,

但其实可以理解为一个函数,内部包含实现的功能。

import java.util.Arrays;
import java.util.Scanner;
class S implements Comparable
{
	int t;
	String s;
	public S(String s,int t)
	{
		this.s=s;
		this.t=t;
	}
	public int compareTo(S a)
	{
		if(this.t-a.t>0)
		return this.t-a.t;
		//else return a.t-this.t;
		else return this.t-a.t;
	}
}
public class Main {

	public static void main(String[] args) {
		
		Scanner reader = new Scanner(System.in);
		int i,n,t;
		n = reader.nextInt();
		String s;
		S d[] = new S[55];
		for(i=0;i=0;i--)
		{
			System.out.println(d[i].s+" "+d[i].t);
		}
		reader.close();

	}

}

 

你可能感兴趣的:(java入门)