File: record.d

package info (click to toggle)
projectl 1.001.dfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,720 kB
  • ctags: 5
  • sloc: xml: 57; makefile: 32
file content (91 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module util.record;
private import std.stream;

public class Record{
	
	public:
	int[][] lapTime;
	int[][] totalTime;
	
	public this(int stage ,int rank){
		lapTime.length = stage;
		totalTime.length = stage;
		foreach(ref int[] lap;lapTime){
			lap.length = rank;
			
		}
		foreach(ref int[] total;totalTime){
			total.length = rank;
			
		}
		start();
	}
	public void start(){
		foreach(ref int[] lap;lapTime){
			foreach(ref int l;lap){
				l = 359999;
			}
		}
		foreach(ref int[] total;totalTime){
			foreach(ref int t;total){
				t = 359999;
			}
		}
	}
	public void load(File fd){
		foreach(ref int[] lap;lapTime){
			foreach(ref int l;lap){
				fd.read(l);
			}
		}
		foreach(ref int[] total;totalTime){
			foreach(ref int t;total){
				fd.read(t);
			}
		}
	}
	public void save(File fd){
		foreach(ref int[] lap;lapTime){
			foreach(ref int l;lap){
				fd.write(l);
			}
		}
		foreach(ref int[] total;totalTime){
			foreach(ref int t;total){
				fd.write(t);
			}
		}
	}
	public int updateLapRecord(int stage ,int lap){
		int rank = -1;
		if(lapTime.length <= stage)return -1;
		for(int i=0;i<lapTime[stage].length;i++){
			if(lap < lapTime[stage][i]){
				rank = i+1;
				for(ptrdiff_t j=lapTime[stage].length-1;i<j;j--){
					lapTime[stage][j] = lapTime[stage][j-1];
				}
				lapTime[stage][i] = lap;
				return rank;
			}
			
		}
		return rank;
	}
	public int updateTotalRecord(int stage ,int total){
		int rank = -1;
		if(totalTime.length <= stage)return -1;
		for(int i=0;i<totalTime[stage].length;i++){
			if(total < totalTime[stage][i]){
				rank = i+1;
				for(ptrdiff_t j=totalTime[stage].length-1;i<j;j--){
					totalTime[stage][j] = totalTime[stage][j-1];
				}
				totalTime[stage][i] = total;
				return rank;
			}
			
		}
		return rank;
	}
}