forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeTemplate.cs
More file actions
83 lines (82 loc) · 2.4 KB
/
CodeTemplate.cs
File metadata and controls
83 lines (82 loc) · 2.4 KB
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
$BEGINCUT$
$PROBLEMDESC$
$ENDCUT$
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
public class $CLASSNAME$ {
public $RC$ $METHODNAME$($METHODPARMS$) {
$RC$ res;
return res;
}
$WRITERCODE$
$BEGINCUT$
public static void Main(String[] args) {
try {
$MAINBODY$
}
catch( Exception exx) {
System.Console.WriteLine(exx);
System.Console.WriteLine( exx.StackTrace);
}
}
private static void eq( int n, object have, object need) {
if( eq( have, need ) ) {
Console.WriteLine( "Case "+n+" passed." );
} else {
Console.Write( "Case "+n+" failed: expected " );
print( need );
Console.Write( ", received " );
print( have );
Console.WriteLine();
}
}
private static void eq( int n, Array have, Array need) {
if( have == null || have.Length != need.Length ) {
Console.WriteLine("Case "+n+" failed: returned "+have.Length+" elements; expected "+need.Length+" elements.");
print( have );
print( need );
return;
}
for( int i= 0; i < have.Length; i++ ) {
if( ! eq( have.GetValue(i), need.GetValue(i) ) ) {
Console.WriteLine( "Case "+n+" failed. Expected and returned array differ in position "+i );
print( have );
print( need );
return;
}
}
Console.WriteLine("Case "+n+" passed.");
}
private static bool eq( object a, object b ) {
if ( a is double && b is double ) {
return Math.Abs((double)a-(double)b) < 1E-9;
} else {
return a!=null && b!=null && a.Equals(b);
}
}
private static void print( object a ) {
if ( a is string ) {
Console.Write("\"{0}\"", a);
} else if ( a is long ) {
Console.Write("{0}L", a);
} else {
Console.Write(a);
}
}
private static void print( Array a ) {
if ( a == null) {
Console.WriteLine("<NULL>");
}
Console.Write('{');
for ( int i= 0; i < a.Length; i++ ) {
print( a.GetValue(i) );
if( i != a.Length-1 ) {
Console.Write(", ");
}
}
Console.WriteLine( '}' );
}
$ENDCUT$
}