萌新求助
  • 板块学术版
  • 楼主依言为定
  • 当前回复1
  • 已保存回复1
  • 发布时间2020/10/16 22:21
  • 上次更新2023/11/5 10:37:25
查看原帖
萌新求助
311491
依言为定楼主2020/10/16 22:21

题目:https://www.luogu.com.cn/problem/P5661

抛出异常:

Exception in thread "main" java.lang.NullPointerException at Main.main(Main.java:11)

代码:

import java.util.*;
public class Main {

	public static void main(String [] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner (System.in);
		Ticket t[] = new Ticket [100005];
		History a[] = new History [100005];
		int n=sc.nextInt(),ans=0;
		for (int i = 0 ; i < n ; i++) {
			a[i].Class=sc.nextInt();
			a[i].price=sc.nextInt();
			a[i].time=sc.nextInt();
		}
		
		for (int i = 0 ; i < n ; i++) {
			if (a[i].Class==0) {
				t[t.length].price = a[i].price;
				t[t.length].time = a[i].time;
			}
			else {
				for (int j = 0 ; j < t.length ; j++) {
					if (a[i].time - 45 <= t[j].time && ( a[i].price <= t[j].price && t[j].used==true ) ) {
						ans -= a[i].price;
						t[j].used = false;
						break;
					}
				}
				ans += a[i].price;
			}
		}
		System.out.print(ans);
		sc.close();
	}

}
class Ticket{
	int time=0;
	int price=0;
	boolean used=true;
}
class History{
	int time=0;
	int price=0;
	int Class=0;
}


2020/10/16 22:21
加载中...