标签:
-----------------------------------------
这道题有坑,就是打印的顺序必须是和输入的顺序一致,这就是他所谓的不排序的意思,瞬间将复杂度提高出题人真是“好水平”....
AC代码:
1 import java.util.ArrayList; 2 import java.util.List; 3 import java.util.Scanner; 4 5 public class Main { 6 7 public static void main(String[] args) { 8 9 Scanner sc=new Scanner(System.in); 10 11 List<Record> list=new ArrayList<Record>(); 12 while(true){ 13 14 int a=sc.nextInt(); 15 int b=sc.nextInt(); 16 17 if(a==0 && b==0){ 18 for(int i=0;i<list.size();i++){ 19 Record t=list.get(i); 20 System.out.println(t.region+" "+t.count); 21 } 22 return; 23 }else{ 24 int t=list.indexOf(new Record(a)); 25 if(t!=-1){ 26 list.get(t).count+=b; 27 }else{ 28 list.add(new Record(a,b)); 29 } 30 } 31 } 32 } 33 34 static class Record{ 35 int region; 36 int count; 37 public Record(int region) { 38 this.region = region; 39 } 40 public Record(int region, int count) { 41 this.region = region; 42 this.count = count; 43 } 44 @Override 45 public boolean equals(Object obj) { 46 Record t=(Record)obj; 47 return this.region==t.region; 48 } 49 } 50 51 }
题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=845
标签:
原文地址:http://www.cnblogs.com/cc11001100/p/5870453.html