additional test cases
This commit is contained in:
parent
1bbad18f52
commit
4458c23fc7
@ -1,98 +0,0 @@
|
||||
// float global constants
|
||||
const float RADIUS = 5.5, PI = 03.141592653589793, EPS = 1e-6;
|
||||
|
||||
// hexadecimal float constant
|
||||
const float PI_HEX = 0x1.921fb6p+1, HEX2 = 0x.AP-3;
|
||||
|
||||
// float constant evaluation
|
||||
const float FACT = -.33E+5, EVAL1 = PI * RADIUS * RADIUS, EVAL2 = 2 * PI_HEX * RADIUS, EVAL3 = PI * 2 * RADIUS;
|
||||
|
||||
// float constant implicit conversion
|
||||
const float CONV1 = 233, CONV2 = 0xfff;
|
||||
const int MAX = 1e9, TWO = 2.9, THREE = 3.2, FIVE = TWO + THREE;
|
||||
|
||||
// float -> float function
|
||||
float float_abs(float x) {
|
||||
if (x < 0) return -x;
|
||||
return x;
|
||||
}
|
||||
|
||||
// int -> float function & float/int expression
|
||||
float circle_area(int radius) {
|
||||
return (PI * radius * radius + (radius * radius) * PI) / 2;
|
||||
}
|
||||
|
||||
// float -> float -> int function & float/int expression
|
||||
int float_eq(float a, float b) {
|
||||
if (float_abs(a - b) < EPS) {
|
||||
return 1 * 2. / 2;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void error() {
|
||||
putch(101);
|
||||
putch(114);
|
||||
putch(114);
|
||||
putch(111);
|
||||
putch(114);
|
||||
putch(10);
|
||||
}
|
||||
|
||||
void ok() {
|
||||
putch(111);
|
||||
putch(107);
|
||||
putch(10);
|
||||
}
|
||||
|
||||
void assert(int cond) {
|
||||
if (!cond) {
|
||||
error();
|
||||
} else {
|
||||
ok();
|
||||
}
|
||||
}
|
||||
|
||||
void assert_not(int cond) {
|
||||
if (cond) {
|
||||
error();
|
||||
} else {
|
||||
ok();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
assert_not(float_eq(HEX2, FACT));
|
||||
assert_not(float_eq(EVAL1, EVAL2));
|
||||
assert(float_eq(EVAL2, EVAL3));
|
||||
assert(float_eq(circle_area(RADIUS) /* f->i implicit conversion */,
|
||||
circle_area(FIVE)));
|
||||
assert_not(float_eq(CONV1, CONV2) /* i->f implicit conversion */);
|
||||
|
||||
// float conditional expressions
|
||||
if (1.5) ok();
|
||||
if (!!3.3) ok();
|
||||
if (.0 && 3) error();
|
||||
if (0 || 0.3) ok();
|
||||
|
||||
// float array & I/O functions
|
||||
int i = 1, p = 0;
|
||||
float arr[10] = {1., 2};
|
||||
int len = getfarray(arr);
|
||||
while (i < MAX) {
|
||||
float input = getfloat();
|
||||
float area = PI * input * input, area_trunc = circle_area(input);
|
||||
arr[p] = arr[p] + input;
|
||||
|
||||
putfloat(area);
|
||||
putch(32);
|
||||
putint(area_trunc); // f->i implicit conversion
|
||||
putch(10);
|
||||
|
||||
i = i * - -1e1;
|
||||
p = p + 1;
|
||||
}
|
||||
putfarray(len, arr);
|
||||
return 0;
|
||||
}
|
||||
3
testcases/functional_test/000_main.sy
Normal file
3
testcases/functional_test/000_main.sy
Normal file
@ -0,0 +1,3 @@
|
||||
int main(){
|
||||
return 3;
|
||||
}
|
||||
7
testcases/functional_test/001_var_defn.sy
Normal file
7
testcases/functional_test/001_var_defn.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test global var define
|
||||
int a = 3;
|
||||
int b = 5;
|
||||
|
||||
int main(){
|
||||
return a + b;
|
||||
}
|
||||
8
testcases/functional_test/002_var_defn2.sy
Normal file
8
testcases/functional_test/002_var_defn2.sy
Normal file
@ -0,0 +1,8 @@
|
||||
//test domain of global var define and local define
|
||||
int a = 3;
|
||||
int b = 5;
|
||||
|
||||
int main(){
|
||||
int a = 5;
|
||||
return a + b;
|
||||
}
|
||||
8
testcases/functional_test/003_var_defn3.sy
Normal file
8
testcases/functional_test/003_var_defn3.sy
Normal file
@ -0,0 +1,8 @@
|
||||
//test local var define
|
||||
int main(){
|
||||
int a, b0, _c;
|
||||
a = 1;
|
||||
b0 = 2;
|
||||
_c = 3;
|
||||
return b0 + _c;
|
||||
}
|
||||
4
testcases/functional_test/004_arr_defn.sy
Normal file
4
testcases/functional_test/004_arr_defn.sy
Normal file
@ -0,0 +1,4 @@
|
||||
int a[10];
|
||||
int main(){
|
||||
return 0;
|
||||
}
|
||||
4
testcases/functional_test/005_arr_defn2.sy
Normal file
4
testcases/functional_test/005_arr_defn2.sy
Normal file
@ -0,0 +1,4 @@
|
||||
int a[10][10];
|
||||
int main(){
|
||||
return 0;
|
||||
}
|
||||
9
testcases/functional_test/006_arr_defn3.sy
Normal file
9
testcases/functional_test/006_arr_defn3.sy
Normal file
@ -0,0 +1,9 @@
|
||||
//test array define
|
||||
int main(){
|
||||
int a[4][2] = {};
|
||||
int b[4][2] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
int c[4][2] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
|
||||
int d[4][2] = {1, 2, {3}, {5}, 7 , 8};
|
||||
int e[4][2] = {{d[2][1], c[2][1]}, {3, 4}, {5, 6}, {7, 8}};
|
||||
return e[3][1] + e[0][0] + e[0][1] + a[2][0];
|
||||
}
|
||||
9
testcases/functional_test/007_arr_defn4.sy
Normal file
9
testcases/functional_test/007_arr_defn4.sy
Normal file
@ -0,0 +1,9 @@
|
||||
int main(){
|
||||
const int a[4][2] = {{1, 2}, {3, 4}, {}, 7};
|
||||
const int N = 3;
|
||||
int b[4][2] = {};
|
||||
int c[4][2] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
int d[N + 1][2] = {1, 2, {3}, {5}, a[3][0], 8};
|
||||
int e[4][2][1] = {{d[2][1], {c[2][1]}}, {3, 4}, {5, 6}, {7, 8}};
|
||||
return e[3][1][0] + e[0][0][0] + e[0][1][0] + d[3][0];
|
||||
}
|
||||
6
testcases/functional_test/008_const_var_defn.sy
Normal file
6
testcases/functional_test/008_const_var_defn.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test global var define
|
||||
const int a = 10;
|
||||
|
||||
int main(){
|
||||
return a;
|
||||
}
|
||||
6
testcases/functional_test/009_const_var_defn2.sy
Normal file
6
testcases/functional_test/009_const_var_defn2.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test const gloal var define
|
||||
const int a = 10, b = 5;
|
||||
|
||||
int main(){
|
||||
return b;
|
||||
}
|
||||
4
testcases/functional_test/00_arr_defn2.sy
Normal file
4
testcases/functional_test/00_arr_defn2.sy
Normal file
@ -0,0 +1,4 @@
|
||||
int a[10][10];
|
||||
int main(){
|
||||
return 0;
|
||||
}
|
||||
3
testcases/functional_test/00_main.sy
Normal file
3
testcases/functional_test/00_main.sy
Normal file
@ -0,0 +1,3 @@
|
||||
int main(){
|
||||
return 0;
|
||||
}
|
||||
5
testcases/functional_test/010_const_var_defn3.sy
Normal file
5
testcases/functional_test/010_const_var_defn3.sy
Normal file
@ -0,0 +1,5 @@
|
||||
//test const local var define
|
||||
int main(){
|
||||
const int a = 10, b = 5;
|
||||
return b;
|
||||
}
|
||||
5
testcases/functional_test/011_const_array_defn.sy
Normal file
5
testcases/functional_test/011_const_array_defn.sy
Normal file
@ -0,0 +1,5 @@
|
||||
const int a[5]={0,1,2,3,4};
|
||||
|
||||
int main(){
|
||||
return a[4];
|
||||
}
|
||||
11
testcases/functional_test/012_func_defn.sy
Normal file
11
testcases/functional_test/012_func_defn.sy
Normal file
@ -0,0 +1,11 @@
|
||||
int a;
|
||||
int func(int p){
|
||||
p = p - 1;
|
||||
return p;
|
||||
}
|
||||
int main(){
|
||||
int b;
|
||||
a = 10;
|
||||
b = func(a);
|
||||
return b;
|
||||
}
|
||||
8
testcases/functional_test/013_var_defn_func.sy
Normal file
8
testcases/functional_test/013_var_defn_func.sy
Normal file
@ -0,0 +1,8 @@
|
||||
int defn(){
|
||||
return 4;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int a=defn();
|
||||
return a;
|
||||
}
|
||||
7
testcases/functional_test/014_add.sy
Normal file
7
testcases/functional_test/014_add.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test add
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 2;
|
||||
return a + b;
|
||||
}
|
||||
7
testcases/functional_test/015_add2.sy
Normal file
7
testcases/functional_test/015_add2.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test add
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = -1;
|
||||
return a + b;
|
||||
}
|
||||
5
testcases/functional_test/016_addc.sy
Normal file
5
testcases/functional_test/016_addc.sy
Normal file
@ -0,0 +1,5 @@
|
||||
//test addc
|
||||
const int a = 10;
|
||||
int main(){
|
||||
return a + 5;
|
||||
}
|
||||
7
testcases/functional_test/017_sub.sy
Normal file
7
testcases/functional_test/017_sub.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test sub
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 2;
|
||||
return a - b;
|
||||
}
|
||||
7
testcases/functional_test/018_sub2.sy
Normal file
7
testcases/functional_test/018_sub2.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test sub
|
||||
const int a = 10;
|
||||
int main(){
|
||||
int b;
|
||||
b = 2;
|
||||
return b - a;
|
||||
}
|
||||
6
testcases/functional_test/019_subc.sy
Normal file
6
testcases/functional_test/019_subc.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test subc
|
||||
int main(){
|
||||
int a;
|
||||
a = 10;
|
||||
return a - 2;
|
||||
}
|
||||
5
testcases/functional_test/01_var_defn.sy
Normal file
5
testcases/functional_test/01_var_defn.sy
Normal file
@ -0,0 +1,5 @@
|
||||
int a;
|
||||
int main(){
|
||||
a=10;
|
||||
return 0;
|
||||
}
|
||||
7
testcases/functional_test/020_mul.sy
Normal file
7
testcases/functional_test/020_mul.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test mul
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 5;
|
||||
return a * b;
|
||||
}
|
||||
5
testcases/functional_test/021_mulc.sy
Normal file
5
testcases/functional_test/021_mulc.sy
Normal file
@ -0,0 +1,5 @@
|
||||
//test mulc
|
||||
const int a = 5;
|
||||
int main(){
|
||||
return a * 5;
|
||||
}
|
||||
7
testcases/functional_test/022_div.sy
Normal file
7
testcases/functional_test/022_div.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test div
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 5;
|
||||
return a / b;
|
||||
}
|
||||
5
testcases/functional_test/023_divc.sy
Normal file
5
testcases/functional_test/023_divc.sy
Normal file
@ -0,0 +1,5 @@
|
||||
//test divc
|
||||
const int a = 10;
|
||||
int main(){
|
||||
return a / 5;
|
||||
}
|
||||
6
testcases/functional_test/024_mod.sy
Normal file
6
testcases/functional_test/024_mod.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test mod
|
||||
int main(){
|
||||
int a;
|
||||
a = 10;
|
||||
return a / 3;
|
||||
}
|
||||
6
testcases/functional_test/025_rem.sy
Normal file
6
testcases/functional_test/025_rem.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test rem
|
||||
int main(){
|
||||
int a;
|
||||
a = 10;
|
||||
return a % 3;
|
||||
}
|
||||
9
testcases/functional_test/026_if.sy
Normal file
9
testcases/functional_test/026_if.sy
Normal file
@ -0,0 +1,9 @@
|
||||
int a;
|
||||
|
||||
int main(){
|
||||
a = 10;
|
||||
if( a>0 ){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
testcases/functional_test/027_if2.sy
Normal file
10
testcases/functional_test/027_if2.sy
Normal file
@ -0,0 +1,10 @@
|
||||
int a;
|
||||
int main(){
|
||||
a = 10;
|
||||
if( a>0 ){
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
16
testcases/functional_test/028_if_test1.sy
Normal file
16
testcases/functional_test/028_if_test1.sy
Normal file
@ -0,0 +1,16 @@
|
||||
// test if-else
|
||||
int ifElse() {
|
||||
int a;
|
||||
a = 5;
|
||||
if (a == 5) {
|
||||
a = 25;
|
||||
} else {
|
||||
a = a * 2;
|
||||
}
|
||||
return (a);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
return (ifElse());
|
||||
}
|
||||
25
testcases/functional_test/029_if_test2.sy
Normal file
25
testcases/functional_test/029_if_test2.sy
Normal file
@ -0,0 +1,25 @@
|
||||
// test if-else-if
|
||||
int ifElseIf() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
b = 10;
|
||||
if(a == 6 || b == 0xb) {
|
||||
return a;
|
||||
}
|
||||
else {
|
||||
if (b == 10 && a == 1)
|
||||
a = 25;
|
||||
else if (b == 10 && a == -5)
|
||||
a = a + 15;
|
||||
else
|
||||
a = -+a;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(){
|
||||
putint(ifElseIf());
|
||||
return 0;
|
||||
}
|
||||
5
testcases/functional_test/02_arr_defn4.sy
Normal file
5
testcases/functional_test/02_arr_defn4.sy
Normal file
@ -0,0 +1,5 @@
|
||||
int main(){
|
||||
int a[4][2]={1,2,3,4,5,6,7,8};
|
||||
int b[4][2]={{a[0][0],a[0][1]},{3,4},{5,6},{7,8}};
|
||||
return 0;
|
||||
}
|
||||
8
testcases/functional_test/02_var_defn2.sy
Normal file
8
testcases/functional_test/02_var_defn2.sy
Normal file
@ -0,0 +1,8 @@
|
||||
int a;
|
||||
int b;
|
||||
int main(){
|
||||
a=10;
|
||||
int c;
|
||||
c=10;
|
||||
return 0;
|
||||
}
|
||||
18
testcases/functional_test/030_if_test3.sy
Normal file
18
testcases/functional_test/030_if_test3.sy
Normal file
@ -0,0 +1,18 @@
|
||||
// test if-if-else
|
||||
int ififElse() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
b = 10;
|
||||
if(a == 5)
|
||||
if (b == 10)
|
||||
a = 25;
|
||||
else
|
||||
a = a + 15;
|
||||
|
||||
return (a);
|
||||
}
|
||||
|
||||
int main(){
|
||||
return (ififElse());
|
||||
}
|
||||
18
testcases/functional_test/031_if_test4.sy
Normal file
18
testcases/functional_test/031_if_test4.sy
Normal file
@ -0,0 +1,18 @@
|
||||
// test if-{if-else}
|
||||
int if_ifElse_() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
b = 10;
|
||||
if(a == 5){
|
||||
if (b == 10)
|
||||
a = 25;
|
||||
else
|
||||
a = a + 15;
|
||||
}
|
||||
return (a);
|
||||
}
|
||||
|
||||
int main(){
|
||||
return (if_ifElse_());
|
||||
}
|
||||
18
testcases/functional_test/032_if_test5.sy
Normal file
18
testcases/functional_test/032_if_test5.sy
Normal file
@ -0,0 +1,18 @@
|
||||
// test if-{if}-else
|
||||
int if_if_Else() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
b = 10;
|
||||
if(a == 5){
|
||||
if (b == 10)
|
||||
a = 25;
|
||||
}
|
||||
else
|
||||
a = a + 15;
|
||||
return (a);
|
||||
}
|
||||
|
||||
int main(){
|
||||
return (if_if_Else());
|
||||
}
|
||||
31
testcases/functional_test/033_while_if.sy
Normal file
31
testcases/functional_test/033_while_if.sy
Normal file
@ -0,0 +1,31 @@
|
||||
int get_one(int a) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int deepWhileBr(int a, int b) {
|
||||
int c;
|
||||
c = a + b;
|
||||
while (c < 75) {
|
||||
int d;
|
||||
d = 42;
|
||||
if (c < 100) {
|
||||
c = c + d;
|
||||
if (c > 99) {
|
||||
int e;
|
||||
e = d * 2;
|
||||
if (get_one(0) == 1) {
|
||||
c = e * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int p;
|
||||
p = 2;
|
||||
p = deepWhileBr(p, p);
|
||||
putint(p);
|
||||
return 0;
|
||||
}
|
||||
18
testcases/functional_test/034_while_test1.sy
Normal file
18
testcases/functional_test/034_while_test1.sy
Normal file
@ -0,0 +1,18 @@
|
||||
int doubleWhile() {
|
||||
int i;
|
||||
i = 5;
|
||||
int j;
|
||||
j = 7;
|
||||
while (i < 100) {
|
||||
i = i + 30;
|
||||
while(j < 100){
|
||||
j = j + 6;
|
||||
}
|
||||
j = j - 100;
|
||||
}
|
||||
return (j);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return doubleWhile();
|
||||
}
|
||||
31
testcases/functional_test/035_while_test2.sy
Normal file
31
testcases/functional_test/035_while_test2.sy
Normal file
@ -0,0 +1,31 @@
|
||||
int FourWhile() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
int c;
|
||||
b = 6;
|
||||
c = 7;
|
||||
int d;
|
||||
d = 10;
|
||||
while (a < 20) {
|
||||
a = a + 3;
|
||||
while(b < 10){
|
||||
b = b + 1;
|
||||
while(c == 7){
|
||||
c = c - 1;
|
||||
while(d < 20){
|
||||
d = d + 3;
|
||||
}
|
||||
d = d - 1;
|
||||
}
|
||||
c = c + 1;
|
||||
}
|
||||
b = b - 2;
|
||||
}
|
||||
|
||||
return (a + (b + d) + c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return FourWhile();
|
||||
}
|
||||
55
testcases/functional_test/036_while_test3.sy
Normal file
55
testcases/functional_test/036_while_test3.sy
Normal file
@ -0,0 +1,55 @@
|
||||
int g;
|
||||
int h;
|
||||
int f;
|
||||
int e;
|
||||
int EightWhile() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
int c;
|
||||
b = 6;
|
||||
c = 7;
|
||||
int d;
|
||||
d = 10;
|
||||
while (a < 20) {
|
||||
a = a + 3;
|
||||
while(b < 10){
|
||||
b = b + 1;
|
||||
while(c == 7){
|
||||
c = c - 1;
|
||||
while(d < 20){
|
||||
d = d + 3;
|
||||
while(e > 1){
|
||||
e = e-1;
|
||||
while(f > 2){
|
||||
f = f -2;
|
||||
while(g < 3){
|
||||
g = g +10;
|
||||
while(h < 10){
|
||||
h = h + 8;
|
||||
}
|
||||
h = h-1;
|
||||
}
|
||||
g = g- 8;
|
||||
}
|
||||
f = f + 1;
|
||||
}
|
||||
e = e + 1;
|
||||
}
|
||||
d = d - 1;
|
||||
}
|
||||
c = c + 1;
|
||||
}
|
||||
b = b - 2;
|
||||
}
|
||||
|
||||
return (a + (b + d) + c)-(e + d - g + h);
|
||||
}
|
||||
|
||||
int main() {
|
||||
g = 1;
|
||||
h = 2;
|
||||
e = 4;
|
||||
f = 6;
|
||||
return EightWhile();
|
||||
}
|
||||
15
testcases/functional_test/037_break.sy
Normal file
15
testcases/functional_test/037_break.sy
Normal file
@ -0,0 +1,15 @@
|
||||
//test break
|
||||
int main(){
|
||||
int i;
|
||||
i = 0;
|
||||
int sum;
|
||||
sum = 0;
|
||||
while(i < 100){
|
||||
if(i == 50){
|
||||
break;
|
||||
}
|
||||
sum = sum + i;
|
||||
i = i + 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
16
testcases/functional_test/038_continue.sy
Normal file
16
testcases/functional_test/038_continue.sy
Normal file
@ -0,0 +1,16 @@
|
||||
//test continue
|
||||
int main(){
|
||||
int i;
|
||||
i = 0;
|
||||
int sum;
|
||||
sum = 0;
|
||||
while(i < 100){
|
||||
if(i == 50){
|
||||
i = i + 1;
|
||||
continue;
|
||||
}
|
||||
sum = sum + i;
|
||||
i = i + 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
25
testcases/functional_test/039_while_if_test1.sy
Normal file
25
testcases/functional_test/039_while_if_test1.sy
Normal file
@ -0,0 +1,25 @@
|
||||
// test while-if
|
||||
int whileIf() {
|
||||
int a;
|
||||
a = 0;
|
||||
int b;
|
||||
b = 0;
|
||||
while (a < 100) {
|
||||
if (a == 5) {
|
||||
b = 25;
|
||||
}
|
||||
else if (a == 10) {
|
||||
b = 42;
|
||||
}
|
||||
else {
|
||||
b = a * 2;
|
||||
}
|
||||
a = a + 1;
|
||||
}
|
||||
return (b);
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
return (whileIf());
|
||||
}
|
||||
4
testcases/functional_test/03_arr_defn.sy
Normal file
4
testcases/functional_test/03_arr_defn.sy
Normal file
@ -0,0 +1,4 @@
|
||||
int a[10];
|
||||
int main(){
|
||||
return 0;
|
||||
}
|
||||
8
testcases/functional_test/03_var_defn2.sy
Normal file
8
testcases/functional_test/03_var_defn2.sy
Normal file
@ -0,0 +1,8 @@
|
||||
int a,b;
|
||||
|
||||
int main(){
|
||||
a=10;
|
||||
b=5;
|
||||
int c=a*2+b+3;
|
||||
return c;
|
||||
}
|
||||
23
testcases/functional_test/040_while_if_test2.sy
Normal file
23
testcases/functional_test/040_while_if_test2.sy
Normal file
@ -0,0 +1,23 @@
|
||||
int ifWhile() {
|
||||
int a;
|
||||
a = 0;
|
||||
int b;
|
||||
b = 3;
|
||||
if (a == 5) {
|
||||
while(b == 2){
|
||||
b = b + 2;
|
||||
}
|
||||
b = b + 25;
|
||||
}
|
||||
else
|
||||
while (a < 5) {
|
||||
b = b * 2;
|
||||
a = a + 1;
|
||||
}
|
||||
return (b);
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
return (ifWhile());
|
||||
}
|
||||
25
testcases/functional_test/041_while_if_test3.sy
Normal file
25
testcases/functional_test/041_while_if_test3.sy
Normal file
@ -0,0 +1,25 @@
|
||||
int deepWhileBr(int a, int b) {
|
||||
int c;
|
||||
c = a + b;
|
||||
while (c < 75) {
|
||||
int d;
|
||||
d = 42;
|
||||
if (c < 100) {
|
||||
c = c + d;
|
||||
if (c > 99) {
|
||||
int e;
|
||||
e = d * 2;
|
||||
if (1 == 1) {
|
||||
c = e * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int p;
|
||||
p = 2;
|
||||
return deepWhileBr(p, p);
|
||||
}
|
||||
11
testcases/functional_test/042_arr_expr_len.sy
Normal file
11
testcases/functional_test/042_arr_expr_len.sy
Normal file
@ -0,0 +1,11 @@
|
||||
const int N = -1;
|
||||
int arr[N + 2 * 4 - 99 / 99] = {1, 2, 33, 4, 5, 6};
|
||||
|
||||
int main() {
|
||||
int i = 0, sum = 0;
|
||||
while (i < 6) {
|
||||
sum = sum + arr[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
9
testcases/functional_test/043_op_priority1.sy
Normal file
9
testcases/functional_test/043_op_priority1.sy
Normal file
@ -0,0 +1,9 @@
|
||||
//test the priority of add and mul
|
||||
int main(){
|
||||
int a, b, c, d;
|
||||
a = 10;
|
||||
b = 4;
|
||||
c = 2;
|
||||
d = 2;
|
||||
return c + a * b - d;
|
||||
}
|
||||
9
testcases/functional_test/044_op_priority2.sy
Normal file
9
testcases/functional_test/044_op_priority2.sy
Normal file
@ -0,0 +1,9 @@
|
||||
//test the priority of add and mul
|
||||
int main(){
|
||||
int a, b, c, d;
|
||||
a = 10;
|
||||
b = 4;
|
||||
c = 2;
|
||||
d = 2;
|
||||
return (c + a) * (b - d);
|
||||
}
|
||||
7
testcases/functional_test/045_op_priority3.sy
Normal file
7
testcases/functional_test/045_op_priority3.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test the priority of unary operator and binary operator
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 30;
|
||||
return a - -5 + b + -5;
|
||||
}
|
||||
19
testcases/functional_test/046_op_priority4.sy
Normal file
19
testcases/functional_test/046_op_priority4.sy
Normal file
@ -0,0 +1,19 @@
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int e;
|
||||
int main()
|
||||
{
|
||||
a=getint();
|
||||
b=getint();
|
||||
c=getint();
|
||||
d=getint();
|
||||
e=getint();
|
||||
int flag=0;
|
||||
if(a-b*c!=d-a/c||a*b/c==e+d||a+b+c==d+e)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
15
testcases/functional_test/047_op_priority5.sy
Normal file
15
testcases/functional_test/047_op_priority5.sy
Normal file
@ -0,0 +1,15 @@
|
||||
int a = 1;
|
||||
int b = 0;
|
||||
int c = 1;
|
||||
int d = 2;
|
||||
int e = 4;
|
||||
int main()
|
||||
{
|
||||
int flag=0;
|
||||
if(a * b / c == e + d && a * (a + b) + c <= d + e || a - (b * c) == d - a / c)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
putint(flag);
|
||||
return flag;
|
||||
}
|
||||
13
testcases/functional_test/048_stmt_expr.sy
Normal file
13
testcases/functional_test/048_stmt_expr.sy
Normal file
@ -0,0 +1,13 @@
|
||||
int k;
|
||||
const int n = 10;
|
||||
int main () {
|
||||
int i = 0;
|
||||
k = 1;
|
||||
while (i <= n - 1) {
|
||||
i = i + 1;
|
||||
k + 1;
|
||||
k = k + k;
|
||||
}
|
||||
putint(k);
|
||||
return k;
|
||||
}
|
||||
11
testcases/functional_test/049_unary_op.sy
Normal file
11
testcases/functional_test/049_unary_op.sy
Normal file
@ -0,0 +1,11 @@
|
||||
int main() {
|
||||
int a;
|
||||
a = 10;
|
||||
if (+-!!!a) {
|
||||
a = - - -1;
|
||||
}
|
||||
else {
|
||||
a = 0;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
5
testcases/functional_test/04_const_defn.sy
Normal file
5
testcases/functional_test/04_const_defn.sy
Normal file
@ -0,0 +1,5 @@
|
||||
const int x=4;
|
||||
|
||||
int main(){
|
||||
return x;
|
||||
}
|
||||
11
testcases/functional_test/04_func_defn.sy
Normal file
11
testcases/functional_test/04_func_defn.sy
Normal file
@ -0,0 +1,11 @@
|
||||
int a;
|
||||
int func(int p){
|
||||
p = p - 1;
|
||||
return p;
|
||||
}
|
||||
int main(){
|
||||
int b;
|
||||
a = 10;
|
||||
b = func(a);
|
||||
return b;
|
||||
}
|
||||
14
testcases/functional_test/050_unary_op2.sy
Normal file
14
testcases/functional_test/050_unary_op2.sy
Normal file
@ -0,0 +1,14 @@
|
||||
int main() {
|
||||
int a, b;
|
||||
a = 070;
|
||||
b = 0x4;
|
||||
a = a - - 4 + + b;
|
||||
if (+-!!!a) {
|
||||
a = - - -1;
|
||||
}
|
||||
else {
|
||||
a = 0 + + b;
|
||||
}
|
||||
putint(a);
|
||||
return 0;
|
||||
}
|
||||
15
testcases/functional_test/051_logi_assign.sy
Normal file
15
testcases/functional_test/051_logi_assign.sy
Normal file
@ -0,0 +1,15 @@
|
||||
int a;
|
||||
int b;
|
||||
int main()
|
||||
{
|
||||
a=getint();
|
||||
b=getint();
|
||||
int c;
|
||||
if (a==b&&a!=3) {
|
||||
c = 1;
|
||||
}
|
||||
else {
|
||||
c = 0;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
8
testcases/functional_test/052_comment1.sy
Normal file
8
testcases/functional_test/052_comment1.sy
Normal file
@ -0,0 +1,8 @@
|
||||
//test comment
|
||||
int main(){
|
||||
int a;
|
||||
a = 5;
|
||||
//int b = 4;
|
||||
//a = b + a;
|
||||
return a;
|
||||
}
|
||||
11
testcases/functional_test/053_comment2.sy
Normal file
11
testcases/functional_test/053_comment2.sy
Normal file
@ -0,0 +1,11 @@
|
||||
//test comment
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 2;
|
||||
/*/*
|
||||
b = 1;
|
||||
// b = 2
|
||||
*/
|
||||
return b;
|
||||
}
|
||||
6
testcases/functional_test/054_hex_defn.sy
Normal file
6
testcases/functional_test/054_hex_defn.sy
Normal file
@ -0,0 +1,6 @@
|
||||
// test hexadecimal define
|
||||
int main(){
|
||||
int a;
|
||||
a = 0xf;
|
||||
return a;
|
||||
}
|
||||
7
testcases/functional_test/055_hex_oct_add.sy
Normal file
7
testcases/functional_test/055_hex_oct_add.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test add of hex and oct
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 0xf;
|
||||
b = 0xc;
|
||||
return a + b + 075;
|
||||
}
|
||||
18
testcases/functional_test/056_assign_complex_expr.sy
Normal file
18
testcases/functional_test/056_assign_complex_expr.sy
Normal file
@ -0,0 +1,18 @@
|
||||
// Use complex expression in assign structure
|
||||
int main () {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int result;
|
||||
a = 5;
|
||||
b = 5;
|
||||
c = 1;
|
||||
d = -2;
|
||||
result = (d * 1 / 2) + (a - b) - -(c + 3) % 2;
|
||||
putint(result);
|
||||
result = ((d % 2 + 67) + -(a - b) - -((c + 2) % 2));
|
||||
result = result + 3;
|
||||
putint(result);
|
||||
return 0;
|
||||
}
|
||||
21
testcases/functional_test/057_if_complex_expr.sy
Normal file
21
testcases/functional_test/057_if_complex_expr.sy
Normal file
@ -0,0 +1,21 @@
|
||||
// Use complex expression in if structure
|
||||
int main () {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int result;
|
||||
a = 5;
|
||||
b = 5;
|
||||
c = 1;
|
||||
d = -2;
|
||||
result = 2;
|
||||
if ((d * 1 / 2) < 0 || (a - b) != 0 && (c + 3) % 2 != 0) {
|
||||
putint(result);
|
||||
}
|
||||
if ((d % 2 + 67) < 0 || (a - b) != 0 && (c + 2) % 2 != 0) {
|
||||
result = 4;
|
||||
putint(result);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
21
testcases/functional_test/058_short_circuit.sy
Normal file
21
testcases/functional_test/058_short_circuit.sy
Normal file
@ -0,0 +1,21 @@
|
||||
int g = 0;
|
||||
|
||||
int func(int n) {
|
||||
g = g + n;
|
||||
putint(g);
|
||||
return g;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
i = getint();
|
||||
if (i > 10 && func(i)) i = 1; else i = 0;
|
||||
i = getint();
|
||||
if (i > 11 && func(i)) i = 1; else i = 0;
|
||||
i = getint();
|
||||
if (i <= 99 || func(i)) i = 1; else i = 0;
|
||||
i = getint();
|
||||
if (i <= 100 || func(i)) i = 1; else i = 0;
|
||||
if (!func(99) && func(100)) i = 1; else i = 0;
|
||||
return 0;
|
||||
}
|
||||
26
testcases/functional_test/059_short_circuit2.sy
Normal file
26
testcases/functional_test/059_short_circuit2.sy
Normal file
@ -0,0 +1,26 @@
|
||||
int func(int n) {
|
||||
if (n <= 50) {
|
||||
putint(n);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
putint(n);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
|
||||
if (func(0) == 1 || func(50) == 1 && func(100) == 0)
|
||||
i = 0;
|
||||
else
|
||||
i = 1;
|
||||
|
||||
if (func(50) == 1 && func(40) == 1 || func(1) == 1 )
|
||||
i = 0;
|
||||
else
|
||||
i = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
testcases/functional_test/05_add.sy
Normal file
10
testcases/functional_test/05_add.sy
Normal file
@ -0,0 +1,10 @@
|
||||
int a;
|
||||
int b;
|
||||
|
||||
int main(){
|
||||
a=10;
|
||||
b=20;
|
||||
int c;
|
||||
c = a + b;
|
||||
return c;
|
||||
}
|
||||
5
testcases/functional_test/05_const_array_defn.sy
Normal file
5
testcases/functional_test/05_const_array_defn.sy
Normal file
@ -0,0 +1,5 @@
|
||||
const int a[5]={0,1,2,3,4};
|
||||
|
||||
int main(){
|
||||
return a[4];
|
||||
}
|
||||
27
testcases/functional_test/060_scope.sy
Normal file
27
testcases/functional_test/060_scope.sy
Normal file
@ -0,0 +1,27 @@
|
||||
int a = 7;
|
||||
|
||||
int func() {
|
||||
int b = a;
|
||||
int a = 1;
|
||||
if (a == b) {
|
||||
a = a + 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int result = 0;
|
||||
int i = 0;
|
||||
while (i < 100) {
|
||||
if (func() == 1)
|
||||
result = result + 1;
|
||||
i = i + 1;
|
||||
}
|
||||
if (result < 100)
|
||||
putint(1);
|
||||
else
|
||||
putint(0);
|
||||
return 0;
|
||||
}
|
||||
41
testcases/functional_test/061_sort_test1.sy
Normal file
41
testcases/functional_test/061_sort_test1.sy
Normal file
@ -0,0 +1,41 @@
|
||||
int n;
|
||||
int bubblesort(int arr[])
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
i =0;
|
||||
while(i < n-1){
|
||||
// Last i elements are already in place
|
||||
j = 0;
|
||||
while(j < n-i-1){
|
||||
if (arr[j] > arr[j+1]) {
|
||||
// swap(&arr[j], &arr[j+1]);
|
||||
int tmp;
|
||||
tmp = arr[j+1];
|
||||
arr[j+1] = arr[j];
|
||||
arr[j] = tmp;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
n = 10;
|
||||
int a[10];
|
||||
a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0;
|
||||
a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8;
|
||||
int i;
|
||||
i = bubblesort(a);
|
||||
while (i < n) {
|
||||
int tmp;
|
||||
tmp = a[i];
|
||||
putint(tmp);
|
||||
tmp = 10;
|
||||
putch(tmp);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
39
testcases/functional_test/062_sort_test2.sy
Normal file
39
testcases/functional_test/062_sort_test2.sy
Normal file
@ -0,0 +1,39 @@
|
||||
int n;
|
||||
int insertsort(int a[])
|
||||
{
|
||||
int i;
|
||||
i = 1;
|
||||
while(i<n)
|
||||
{
|
||||
int temp;
|
||||
temp=a[i];
|
||||
int j;
|
||||
j=i-1;
|
||||
while(j>-1&&temp<a[j])
|
||||
{
|
||||
a[j+1]=a[j];
|
||||
j = j - 1;
|
||||
}
|
||||
a[j+1]=temp;
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
n = 10;
|
||||
int a[10];
|
||||
a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0;
|
||||
a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8;
|
||||
int i;
|
||||
i = insertsort(a);
|
||||
while (i < n) {
|
||||
int tmp;
|
||||
tmp = a[i];
|
||||
putint(tmp);
|
||||
tmp = 10;
|
||||
putch(tmp);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
66
testcases/functional_test/063_sort_test3.sy
Normal file
66
testcases/functional_test/063_sort_test3.sy
Normal file
@ -0,0 +1,66 @@
|
||||
int n;
|
||||
int QuickSort(int arr[], int low, int high)
|
||||
{
|
||||
if (low < high)
|
||||
{
|
||||
int i;
|
||||
i = low;
|
||||
int j;
|
||||
j = high;
|
||||
int k;
|
||||
k = arr[low];
|
||||
while (i < j)
|
||||
{
|
||||
while(i < j && arr[j] > k - 1)
|
||||
{
|
||||
j = j - 1;
|
||||
}
|
||||
|
||||
if(i < j)
|
||||
{
|
||||
arr[i] = arr[j];
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
while(i < j && arr[i] < k)
|
||||
{
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
if(i < j)
|
||||
{
|
||||
arr[j] = arr[i];
|
||||
j = j - 1;
|
||||
}
|
||||
}
|
||||
|
||||
arr[i] = k;
|
||||
int tmp;
|
||||
tmp = i - 1;
|
||||
tmp = QuickSort(arr, low, tmp);
|
||||
tmp = i + 1;
|
||||
tmp = QuickSort(arr, tmp, high);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
n = 10;
|
||||
int a[10];
|
||||
a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0;
|
||||
a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8;
|
||||
int i;
|
||||
i = 0;
|
||||
int tmp;
|
||||
tmp = 9;
|
||||
i = QuickSort(a, i, tmp);
|
||||
while (i < n) {
|
||||
int tmp;
|
||||
tmp = a[i];
|
||||
putint(tmp);
|
||||
tmp = 10;
|
||||
putch(tmp);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
49
testcases/functional_test/064_sort_test4.sy
Normal file
49
testcases/functional_test/064_sort_test4.sy
Normal file
@ -0,0 +1,49 @@
|
||||
int n;
|
||||
int select_sort(int A[],int n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int min;
|
||||
i =0;
|
||||
while(i < n-1)
|
||||
{
|
||||
min=i;//
|
||||
j = i + 1;
|
||||
while(j < n)
|
||||
{
|
||||
if(A[min]>A[j])
|
||||
{
|
||||
min=j;
|
||||
}
|
||||
j=j+1;
|
||||
}
|
||||
if(min!=i)
|
||||
{
|
||||
int tmp;
|
||||
tmp = A[min];
|
||||
A[min] = A[i];
|
||||
A[i] = tmp;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
n = 10;
|
||||
int a[10];
|
||||
a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0;
|
||||
a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8;
|
||||
int i;
|
||||
i = 0;
|
||||
i = select_sort(a, n);
|
||||
while (i < n) {
|
||||
int tmp;
|
||||
tmp = a[i];
|
||||
putint(tmp);
|
||||
tmp = 10;
|
||||
putch(tmp);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
65
testcases/functional_test/065_sort_test5.sy
Normal file
65
testcases/functional_test/065_sort_test5.sy
Normal file
@ -0,0 +1,65 @@
|
||||
int n;
|
||||
int swap (int array[], int i, int j){
|
||||
int temp;
|
||||
temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
return 0;
|
||||
}
|
||||
int heap_ajust(int arr[], int start, int end) {
|
||||
int dad;
|
||||
dad = start;
|
||||
int son;
|
||||
son = dad * 2 + 1;
|
||||
while (son < end + 1) { //
|
||||
if (son < end && arr[son] < arr[son + 1])
|
||||
son = son + 1;
|
||||
if (arr[dad] > arr[son])
|
||||
return 0;
|
||||
else {
|
||||
dad = swap(arr,dad,son);
|
||||
dad = son;
|
||||
son = dad * 2 + 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int heap_sort(int arr[], int len) {
|
||||
int i;
|
||||
int tmp;
|
||||
i = len / 2 - 1;
|
||||
while ( i > -1) {
|
||||
tmp = len - 1;
|
||||
tmp = heap_ajust(arr, i, tmp);
|
||||
i = i - 1;
|
||||
}
|
||||
i = len - 1;
|
||||
while ( i > 0) {
|
||||
int tmp0;
|
||||
tmp0 = 0;
|
||||
tmp = swap(arr,tmp0,i);
|
||||
tmp = i - 1;
|
||||
tmp = heap_ajust(arr, tmp0, tmp);
|
||||
i = i-1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
n = 10;
|
||||
int a[10];
|
||||
a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0;
|
||||
a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8;
|
||||
int i;
|
||||
i = 0;
|
||||
i = heap_sort(a, n);
|
||||
while (i < n) {
|
||||
int tmp;
|
||||
tmp = a[i];
|
||||
putint(tmp);
|
||||
tmp = 10;
|
||||
putch(tmp);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
53
testcases/functional_test/066_sort_test6.sy
Normal file
53
testcases/functional_test/066_sort_test6.sy
Normal file
@ -0,0 +1,53 @@
|
||||
int n;
|
||||
|
||||
int counting_sort(int ini_arr[], int sorted_arr[], int n) {
|
||||
int count_arr[10];
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
k = 0;
|
||||
i = 0;
|
||||
j = 0;
|
||||
while(k < 10){
|
||||
count_arr[k] = 0;
|
||||
k = k + 1;
|
||||
}
|
||||
while(i < n)
|
||||
{
|
||||
count_arr[ini_arr[i]] = count_arr[ini_arr[i]] + 1;
|
||||
i = i + 1;
|
||||
}
|
||||
k = 1;
|
||||
while(k < 10){
|
||||
count_arr[k] = count_arr[k] + count_arr[k - 1];
|
||||
k = k + 1;
|
||||
}
|
||||
j = n;
|
||||
while( j > 0){
|
||||
count_arr[ini_arr[j - 1]] = count_arr[ini_arr[j - 1]] - 1;
|
||||
sorted_arr[count_arr[ini_arr[j - 1]]] = ini_arr[j - 1];
|
||||
j = j - 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
n = 10;
|
||||
int a[10];
|
||||
a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0;
|
||||
a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8;
|
||||
int i;
|
||||
i = 0;
|
||||
int b[10];
|
||||
i = counting_sort(a, b, n);
|
||||
while (i < n) {
|
||||
int tmp;
|
||||
tmp = b[i];
|
||||
putint(tmp);
|
||||
tmp = 10;
|
||||
putch(tmp);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
47
testcases/functional_test/067_sort_test7.sy
Normal file
47
testcases/functional_test/067_sort_test7.sy
Normal file
@ -0,0 +1,47 @@
|
||||
int buf[2][100];
|
||||
|
||||
// sort [l, r)
|
||||
void merge_sort(int l, int r)
|
||||
{
|
||||
if (l + 1 >= r)
|
||||
return;
|
||||
|
||||
int mid = (l + r) / 2;
|
||||
merge_sort(l, mid);
|
||||
merge_sort(mid, r);
|
||||
|
||||
int i = l, j = mid, k = l;
|
||||
while (i < mid && j < r) {
|
||||
if (buf[0][i] < buf[0][j]) {
|
||||
buf[1][k] = buf[0][i];
|
||||
i = i + 1;
|
||||
} else {
|
||||
buf[1][k] = buf[0][j];
|
||||
j = j + 1;
|
||||
}
|
||||
k = k + 1;
|
||||
}
|
||||
while (i < mid) {
|
||||
buf[1][k] = buf[0][i];
|
||||
i = i + 1;
|
||||
k = k + 1;
|
||||
}
|
||||
while (j < r) {
|
||||
buf[1][k] = buf[0][j];
|
||||
j = j + 1;
|
||||
k = k + 1;
|
||||
}
|
||||
|
||||
while (l < r) {
|
||||
buf[0][l] = buf[1][l];
|
||||
l = l + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int n = getarray(buf[0]);
|
||||
merge_sort(0, n);
|
||||
putarray(n, buf[0]);
|
||||
return 0;
|
||||
}
|
||||
68
testcases/functional_test/068_genealogical_tree.sy
Normal file
68
testcases/functional_test/068_genealogical_tree.sy
Normal file
@ -0,0 +1,68 @@
|
||||
int map[10][10];
|
||||
int indegree[10];
|
||||
int queue[10];
|
||||
void topo(int n)
|
||||
{
|
||||
int m=0;
|
||||
int t=0;
|
||||
int i,j;
|
||||
i=1;
|
||||
j=1;
|
||||
while(i<=n)
|
||||
{
|
||||
j=1;
|
||||
while(j<=n)
|
||||
{
|
||||
if(indegree[j]==0)
|
||||
{
|
||||
|
||||
m=j;
|
||||
break;
|
||||
}
|
||||
j=j+1;
|
||||
}
|
||||
queue[t]=m;
|
||||
t=t+1;
|
||||
indegree[m]=-1;
|
||||
j=1;
|
||||
while(j<=n)
|
||||
|
||||
{
|
||||
if(map[m][j])
|
||||
{
|
||||
indegree[j]=indegree[j]-1;
|
||||
}
|
||||
j=j+1;
|
||||
}
|
||||
i=i+1;
|
||||
}
|
||||
i=0;
|
||||
while(i<n)
|
||||
{
|
||||
putint(queue[i]);
|
||||
putch(10);
|
||||
i=i+1;
|
||||
}
|
||||
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n,p;
|
||||
int i=1;
|
||||
n=5;
|
||||
|
||||
while(i<=n)
|
||||
{
|
||||
p=getint();
|
||||
while(p!=0)
|
||||
{
|
||||
map[i][p]=1;
|
||||
indegree[p]=indegree[p]+1;
|
||||
p=getint();
|
||||
|
||||
}
|
||||
i=i+1;
|
||||
}
|
||||
topo(n);
|
||||
return 0;
|
||||
}
|
||||
19
testcases/functional_test/069_greatest_common_divisor.sy
Normal file
19
testcases/functional_test/069_greatest_common_divisor.sy
Normal file
@ -0,0 +1,19 @@
|
||||
int fun(int m,int n){
|
||||
int rem;
|
||||
while(n > 0){
|
||||
rem = m % n;
|
||||
m = n;
|
||||
n = rem;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
int main(){
|
||||
int n,m;
|
||||
int num;
|
||||
m=getint();
|
||||
n=getint();
|
||||
num=fun(m,n);
|
||||
putint(num);
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
testcases/functional_test/06_mod.sy
Normal file
9
testcases/functional_test/06_mod.sy
Normal file
@ -0,0 +1,9 @@
|
||||
int a;
|
||||
int b;
|
||||
int main(){
|
||||
a = 10;
|
||||
b = 3;
|
||||
int c;
|
||||
c = a % b;
|
||||
return c;
|
||||
}
|
||||
8
testcases/functional_test/06_var_defn_func.sy
Normal file
8
testcases/functional_test/06_var_defn_func.sy
Normal file
@ -0,0 +1,8 @@
|
||||
int defn(){
|
||||
return 4;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int a=defn();
|
||||
return a;
|
||||
}
|
||||
32
testcases/functional_test/070_multiplication_puzzle.sy
Normal file
32
testcases/functional_test/070_multiplication_puzzle.sy
Normal file
@ -0,0 +1,32 @@
|
||||
int a[6]={10,1,50,50,20,5};
|
||||
int dp[10][10];
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
n=6;
|
||||
|
||||
int k,i,t,j,aa;
|
||||
k=3;
|
||||
while(k<=n)
|
||||
{
|
||||
i=0;
|
||||
while(i<n-k+1)
|
||||
{
|
||||
j=i+k-1;
|
||||
t=i+1;
|
||||
while(t<j)
|
||||
{
|
||||
aa= dp[i][t]+dp[t][j]+a[i]*a[t]*a[j];
|
||||
if(!dp[i][j]||aa<dp[i][j])
|
||||
{
|
||||
dp[i][j]=aa;
|
||||
}
|
||||
t=t+1;
|
||||
}
|
||||
i=i+1;
|
||||
}
|
||||
k=k+1;
|
||||
}
|
||||
putint(dp[0][n-1]);
|
||||
return 0;
|
||||
}
|
||||
14
testcases/functional_test/071_exchange_array.sy
Normal file
14
testcases/functional_test/071_exchange_array.sy
Normal file
@ -0,0 +1,14 @@
|
||||
int main(){
|
||||
int a[5][5] = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5};
|
||||
int m, n, i, j;
|
||||
m = 2;
|
||||
n = 3;
|
||||
j = 0;
|
||||
while(j < 5){
|
||||
i = a[m-1][j];
|
||||
a[m-1][j] = a[n-1][j];
|
||||
a[n-1][j] = i;
|
||||
j = j + 1;
|
||||
}
|
||||
return a[2][0];
|
||||
}
|
||||
82
testcases/functional_test/072_percolation.sy
Normal file
82
testcases/functional_test/072_percolation.sy
Normal file
@ -0,0 +1,82 @@
|
||||
int array[110];
|
||||
int n;
|
||||
void init(int n) {
|
||||
int i = 1;
|
||||
while (i <= n * n + 1) {
|
||||
array[i] = -1;
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int findfa(int a) {
|
||||
if (array[a] == a)
|
||||
return a;
|
||||
else {
|
||||
array[a] = findfa(array[a]);
|
||||
return array[a];
|
||||
}
|
||||
}
|
||||
void mmerge(int a, int b) {
|
||||
int m = findfa(a);
|
||||
int n = findfa(b);
|
||||
if (m != n) array[m] = n;
|
||||
}
|
||||
int main() {
|
||||
int t, m;
|
||||
int a, b;
|
||||
t = 1;
|
||||
while (t) {
|
||||
t = t - 1;
|
||||
n = 4;
|
||||
m = 10;
|
||||
int i = 0;
|
||||
int flag = 0;
|
||||
init(n);
|
||||
int k = n * n + 1;
|
||||
|
||||
while (i < m) {
|
||||
a = getint();
|
||||
b = getint();
|
||||
|
||||
if (!flag) {
|
||||
int loc = n * (a - 1) + b;
|
||||
|
||||
array[loc] = loc;
|
||||
if (a == 1) {
|
||||
array[0] = 0;
|
||||
mmerge(loc, 0);
|
||||
}
|
||||
if (a == n) {
|
||||
array[k] = k;
|
||||
mmerge(loc, k);
|
||||
}
|
||||
if (b < n && array[loc + 1] != -1) {
|
||||
mmerge(loc, loc + 1);
|
||||
}
|
||||
if (b > 1 && array[loc - 1] != -1) {
|
||||
mmerge(loc, loc - 1);
|
||||
}
|
||||
if (a < n && array[loc + n] != -1) {
|
||||
mmerge(loc, loc + n);
|
||||
}
|
||||
if (a > 1 && array[loc - n] != -1) {
|
||||
mmerge(loc, loc - n);
|
||||
}
|
||||
|
||||
if (array[0] != -1 && array[k] != -1 && findfa(0) == findfa(k)) {
|
||||
flag = 1;
|
||||
int tmp = i + 1;
|
||||
putint(tmp);
|
||||
putch(10);
|
||||
}
|
||||
}
|
||||
|
||||
i = i + 1;
|
||||
}
|
||||
if (!flag) {
|
||||
putint(-1);
|
||||
putch(10);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
63
testcases/functional_test/073_backpack.sy
Normal file
63
testcases/functional_test/073_backpack.sy
Normal file
@ -0,0 +1,63 @@
|
||||
int V[200][200]={};
|
||||
int KnapSack(int n, int w[], int v[], int x[], int C)
|
||||
{
|
||||
int i, j;
|
||||
i=1;
|
||||
while(i<=n)
|
||||
{
|
||||
j=0;
|
||||
while(j<C+1)
|
||||
{
|
||||
if (j<w[i])
|
||||
V[i][j] = V[i - 1][j];
|
||||
else
|
||||
{
|
||||
int tmp1=V[i - 1][j];
|
||||
int tmp2=V[i - 1][j - w[i]] + v[i];
|
||||
if(tmp1>tmp2)
|
||||
{
|
||||
V[i][j] = tmp1;
|
||||
}
|
||||
else
|
||||
{
|
||||
V[i][j] = tmp2;
|
||||
}
|
||||
|
||||
}
|
||||
j=j+1;
|
||||
}
|
||||
i=i+1;
|
||||
}
|
||||
|
||||
j = C;
|
||||
i=n;
|
||||
while(i>=1)
|
||||
{
|
||||
if (V[i][j]>V[i - 1][j])
|
||||
{
|
||||
x[i] = 1;
|
||||
j = j - w[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
x[i] = 0;
|
||||
}
|
||||
i=i-1;
|
||||
}
|
||||
return V[n][C];
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int s;
|
||||
int w[6] = {0,2,2,6,5,4};
|
||||
int v[6] = {0,6,3,5,4,6};
|
||||
int x[6];
|
||||
int n = 5;
|
||||
int C=10;
|
||||
s = KnapSack(n, w, v, x, C);
|
||||
putint(s);
|
||||
return 0;
|
||||
|
||||
}
|
||||
@ -3,7 +3,7 @@ int L;
|
||||
int N;
|
||||
|
||||
|
||||
int add(float a0[],float a1[], float a2[],float b0[],float b1[],float b2[],float c0[],float c1[],float c2[])
|
||||
int add(int a0[],int a1[], int a2[],int b0[],int b1[],int b2[],int c0[],int c1[],int c2[])
|
||||
{
|
||||
int i;
|
||||
i=0;
|
||||
@ -24,7 +24,7 @@ int main()
|
||||
N=3;
|
||||
M=3;
|
||||
L=3;
|
||||
float a0[3], a1[3], a2[3], b0[3], b1[3], b2[3], c0[6], c1[3], c2[3];
|
||||
int a0[3];int a1[3]; int a2[3];int b0[3];int b1[3];int b2[3];int c0[6];int c1[3];int c2[3];
|
||||
int i;
|
||||
i=0;
|
||||
while(i<M)
|
||||
@ -2,7 +2,7 @@ int N;
|
||||
int M;
|
||||
int L;
|
||||
|
||||
int sub(float a0[],float a1[], float a2[],float b0[],float b1[],float b2[],float c0[],float c1[],float c2[])
|
||||
int sub(int a0[],int a1[], int a2[],int b0[],int b1[],int b2[],int c0[],int c1[],int c2[])
|
||||
{
|
||||
int i;
|
||||
i=0;
|
||||
@ -21,9 +21,9 @@ int sub(float a0[],float a1[], float a2[],float b0[],float b1[],float b2[],float
|
||||
int main()
|
||||
{
|
||||
N=3;
|
||||
M=3;
|
||||
L=3;
|
||||
float a0[3], a1[3], a2[3], b0[3], b1[3], b2[3], c0[6], c1[3], c2[3];
|
||||
M=3;
|
||||
L=3;
|
||||
int a0[3];int a1[3]; int a2[3];int b0[3];int b1[3];int b2[3];int c0[6];int c1[3];int c2[3];
|
||||
int i;
|
||||
i=0;
|
||||
while(i<3)
|
||||
@ -3,7 +3,7 @@ int L;
|
||||
int N;
|
||||
|
||||
|
||||
int mul(float a0[],float a1[], float a2[],float b0[],float b1[],float b2[],float c0[],float c1[],float c2[])
|
||||
int mul(int a0[],int a1[], int a2[],int b0[],int b1[],int b2[],int c0[],int c1[],int c2[])
|
||||
{
|
||||
int i;
|
||||
i=0;
|
||||
@ -26,7 +26,7 @@ int main()
|
||||
N=3;
|
||||
M=3;
|
||||
L=3;
|
||||
float a0[3], a1[3], a2[3], b0[3], b1[3], b2[3], c0[6], c1[3], c2[3];
|
||||
int a0[3];int a1[3]; int a2[3];int b0[3];int b1[3];int b2[3];int c0[6];int c1[3];int c2[3];
|
||||
int i;
|
||||
i=0;
|
||||
while(i<M)
|
||||
@ -2,7 +2,7 @@ int M;
|
||||
int L;
|
||||
int N;
|
||||
|
||||
int tran(float a0[],float a1[], float a2[],float b0[],float b1[],float b2[],float c0[],float c1[],float c2[])
|
||||
int tran(int a0[],int a1[], int a2[],int b0[],int b1[],int b2[],int c0[],int c1[],int c2[])
|
||||
{
|
||||
int i;
|
||||
i=0;
|
||||
@ -25,7 +25,7 @@ int main()
|
||||
N=3;
|
||||
M=3;
|
||||
L=3;
|
||||
float a0[3], a1[3], a2[3], b0[3], b1[3], b2[3], c0[6], c1[3], c2[3];
|
||||
int a0[3];int a1[3]; int a2[3];int b0[3];int b1[3];int b2[3];int c0[6];int c1[3];int c2[3];
|
||||
int i;
|
||||
i=0;
|
||||
while(i<M)
|
||||
65
testcases/functional_test/078_big_int_mul.sy
Normal file
65
testcases/functional_test/078_big_int_mul.sy
Normal file
@ -0,0 +1,65 @@
|
||||
const int len = 20;
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, j, t, n, temp;
|
||||
int mult1[len] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
|
||||
int mult2[len] = {2, 3, 4, 2, 5, 7 ,9 ,9, 0, 1, 9, 8, 7, 6, 4, 3, 2, 1, 2, 2};
|
||||
int len1 = len;
|
||||
int len2 = len;
|
||||
int c1[len + 5];
|
||||
int c2[len + 5];
|
||||
int result[len * 2] = {};
|
||||
|
||||
i = 0;
|
||||
while (i < len1) {
|
||||
c1[i] = mult1[i];
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < len2) {
|
||||
c2[i] = mult2[i];
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
n = len1 + len2 - 1;
|
||||
|
||||
i = 0;
|
||||
while (i <= n) {
|
||||
result[i]=0;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
temp=0;
|
||||
|
||||
i = len2 - 1;
|
||||
while (i > -1) {
|
||||
t = c2[i];
|
||||
j = len1 - 1;
|
||||
while (j > -1) {
|
||||
temp = result[n] + t * c1[j];
|
||||
if(temp >= 10) {
|
||||
result[n] = (temp);
|
||||
result[n-1] = result[n-1] + temp / 10;
|
||||
}
|
||||
else
|
||||
result[n] = temp;
|
||||
j = j - 1;
|
||||
n = n - 1;
|
||||
}
|
||||
n = n + len1 - 1;
|
||||
i = i - 1;
|
||||
}
|
||||
|
||||
if(result[0] != 0)
|
||||
putint(result[0]);
|
||||
|
||||
i = 1;
|
||||
while (i <= len1 + len2 - 1) {
|
||||
putint(result[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
184
testcases/functional_test/079_calculator.sy
Normal file
184
testcases/functional_test/079_calculator.sy
Normal file
@ -0,0 +1,184 @@
|
||||
int ints[10000];
|
||||
int intt;
|
||||
int chas[10000];
|
||||
int chat;
|
||||
int i=0, ii=1;
|
||||
int c;
|
||||
int get[10000];
|
||||
int get2[10000];
|
||||
|
||||
int isdigit(int x) {
|
||||
if (x >= 48 && x <= 57)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int power(int b, int a) {
|
||||
int result = 1;
|
||||
while (a != 0) {
|
||||
result = result * b;
|
||||
a = a - 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int getstr(int get[]) {
|
||||
int x = getch();
|
||||
int length = 0;
|
||||
while (x != 13 && x != 10) {
|
||||
get[length] = x;
|
||||
length = length + 1;
|
||||
x = getch();
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
void intpush(int x)
|
||||
{
|
||||
intt = intt + 1;
|
||||
ints[intt] = x;
|
||||
}
|
||||
void chapush(int x)
|
||||
{
|
||||
chat = chat + 1;
|
||||
chas[chat] = x;
|
||||
}
|
||||
int intpop()
|
||||
{
|
||||
intt = intt - 1;
|
||||
return ints[intt + 1];
|
||||
}
|
||||
int chapop()
|
||||
{
|
||||
chat = chat - 1;
|
||||
return chas[chat + 1];
|
||||
}
|
||||
void intadd(int x)
|
||||
{
|
||||
ints[intt] = ints[intt] * 10;
|
||||
ints[intt] = ints[intt] + x;
|
||||
}
|
||||
|
||||
int find()
|
||||
{
|
||||
c = chapop();
|
||||
get2[ii] = 32;
|
||||
get2[ii + 1] = c;
|
||||
ii = ii + 2;
|
||||
if (chat == 0) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
intt=0;
|
||||
chat=0;
|
||||
int lengets = getstr(get);
|
||||
while (i < lengets)
|
||||
{
|
||||
if (isdigit(get[i]) == 1)
|
||||
{
|
||||
get2[ii] = get[i];
|
||||
ii = ii + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(get[i] == 40) chapush(40);
|
||||
if(get[i] == 94) chapush(94);
|
||||
if(get[i] == 41)
|
||||
{
|
||||
c = chapop();
|
||||
while (c != 40)
|
||||
{
|
||||
get2[ii] = 32;
|
||||
get2[ii + 1]=c;
|
||||
ii = ii + 2;
|
||||
c = chapop();
|
||||
}
|
||||
}
|
||||
if (get[i] == 43)
|
||||
{
|
||||
while (chas[chat] == 43 || chas[chat] == 45 || chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94)
|
||||
{
|
||||
if (find()==0)break;
|
||||
}
|
||||
chapush(43);
|
||||
}
|
||||
if (get[i] == 45)
|
||||
{
|
||||
while (chas[chat] == 43 || chas[chat] == 45 ||chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94)
|
||||
{
|
||||
if(find()==0)break;
|
||||
}
|
||||
chapush(45);
|
||||
}
|
||||
if(get[i] == 42)
|
||||
{
|
||||
while (chas[chat] == 42 || chas[chat] == 47 ||chas[chat] == 37 || chas[chat] == 94)
|
||||
{
|
||||
if (find()==0)break;
|
||||
}
|
||||
chapush(42);
|
||||
}
|
||||
if (get[i] == 47)
|
||||
{
|
||||
while (chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94)
|
||||
{
|
||||
if (find()==0)break;
|
||||
}
|
||||
chapush(47);
|
||||
}
|
||||
if (get[i] == 37)
|
||||
{
|
||||
while (chas[chat] == 42 || chas[chat] == 47 || chas[chat] == 37 || chas[chat] == 94)
|
||||
{
|
||||
if (find()==0)break;
|
||||
}
|
||||
chapush(37);
|
||||
}
|
||||
get2[ii] = 32;
|
||||
ii = ii + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
while(chat > 0)
|
||||
{
|
||||
int c = chapop();
|
||||
get2[ii] = 32;
|
||||
get2[ii + 1]=c;
|
||||
ii = ii + 2;
|
||||
}
|
||||
get2[ii]= 64;
|
||||
i = 1;
|
||||
while (get2[i] != 64)
|
||||
{
|
||||
if (get2[i] == 43 || get2[i] == 45 || get2[i] == 42 || get2[i] == 47 || get2[i] == 37 || get2[i] == 94)
|
||||
{
|
||||
int a=intpop();int b=intpop();int c;
|
||||
if (get2[i] == 43) c = a + b;
|
||||
if (get2[i] == 45) c = b - a;
|
||||
if (get2[i] == 42) c = a * b;
|
||||
if (get2[i] == 47) c = b / a;
|
||||
if (get2[i] == 37) c = b % a;
|
||||
if (get2[i] == 94) c = power(b,a);
|
||||
intpush(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(get2[i] != 32)
|
||||
{
|
||||
intpush(get2[i] - 48);
|
||||
ii=1;
|
||||
while(get2[i+ii] != 32)
|
||||
{
|
||||
intadd(get2[i+ii] - 48);
|
||||
ii = ii + 1;
|
||||
}
|
||||
i = i + ii-1;
|
||||
}
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
putint(ints[1]);
|
||||
return 0;
|
||||
}
|
||||
6
testcases/functional_test/07_comment1.sy
Normal file
6
testcases/functional_test/07_comment1.sy
Normal file
@ -0,0 +1,6 @@
|
||||
int main(){
|
||||
//this is a single line comment
|
||||
//int a;
|
||||
//a=5;
|
||||
return 0;
|
||||
}
|
||||
6
testcases/functional_test/07_return_var.sy
Normal file
6
testcases/functional_test/07_return_var.sy
Normal file
@ -0,0 +1,6 @@
|
||||
int a;
|
||||
|
||||
int main(){
|
||||
a=10;
|
||||
return a;
|
||||
}
|
||||
69
testcases/functional_test/080_color.sy
Normal file
69
testcases/functional_test/080_color.sy
Normal file
@ -0,0 +1,69 @@
|
||||
const int maxn = 18;
|
||||
const int mod = 1000000007;
|
||||
int dp[maxn][maxn][maxn][maxn][maxn][7];
|
||||
int list[200];
|
||||
|
||||
int equal(int a, int b) {
|
||||
if (a == b)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dfs(int a, int b, int c, int d, int e, int last){
|
||||
if(dp[a][b][c][d][e][last] != -1)
|
||||
return dp[a][b][c][d][e][last];
|
||||
if(a + b + c + d + e == 0)
|
||||
return 1;
|
||||
int ans = 0;
|
||||
if (a) ans = (ans + (a - equal(last, 2)) * dfs(a - 1, b, c, d, e, 1)) % mod;
|
||||
if (b) ans = (ans + (b - equal(last, 3)) * dfs(a + 1, b - 1, c, d, e, 2)) % mod;
|
||||
if (c) ans = (ans + (c - equal(last, 4)) * dfs(a, b + 1, c - 1, d, e, 3)) % mod;
|
||||
if (d) ans = (ans + (d - equal(last, 5)) * dfs(a, b, c + 1, d - 1, e, 4)) % mod;
|
||||
if (e) ans = (ans + e * dfs(a, b, c, d + 1, e - 1, 5)) % mod;
|
||||
dp[a][b][c][d][e][last] = ans % mod;
|
||||
return dp[a][b][c][d][e][last];
|
||||
}
|
||||
|
||||
int cns[20];
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int i = 0;
|
||||
while (i < maxn) {
|
||||
int j = 0;
|
||||
while(j < maxn) {
|
||||
int k = 0;
|
||||
while(k < maxn) {
|
||||
int l = 0;
|
||||
while (l < maxn) {
|
||||
int m = 0;
|
||||
while (m < maxn) {
|
||||
int h = 0;
|
||||
while (h < 7) {
|
||||
dp[i][j][k][l][m][h] = -1;
|
||||
h = h + 1;
|
||||
}
|
||||
m = m + 1;
|
||||
}
|
||||
l = l + 1;
|
||||
}
|
||||
k = k + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n) {
|
||||
list[i] = getint();
|
||||
cns[list[i]] = cns[list[i]] + 1;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
int ans = dfs(cns[1], cns[2], cns[3], cns[4], cns[5], 0);
|
||||
|
||||
putint(ans);
|
||||
|
||||
return ans;
|
||||
}
|
||||
22
testcases/functional_test/081_exgcd.sy
Normal file
22
testcases/functional_test/081_exgcd.sy
Normal file
@ -0,0 +1,22 @@
|
||||
int exgcd(int a,int b,int x[],int y[]) {
|
||||
if(b == 0) {
|
||||
x[0] = 1;
|
||||
y[0] = 0;
|
||||
return a;
|
||||
}
|
||||
else {
|
||||
int r = exgcd(b, a % b, x, y);
|
||||
int t = x[0];
|
||||
x[0] = y[0];
|
||||
y[0] = (t - a / b * y[0]);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a = 7, b = 15, x[1] = {1}, y[1] = {1};
|
||||
exgcd(a, b, x, y);
|
||||
x[0] = (x[0] % b + b) % b;
|
||||
putint(x[0]);
|
||||
return 0;
|
||||
}
|
||||
18
testcases/functional_test/082_reverse_output.sy
Normal file
18
testcases/functional_test/082_reverse_output.sy
Normal file
@ -0,0 +1,18 @@
|
||||
void reverse(int n) {
|
||||
int next;
|
||||
if (n <= 1) {
|
||||
next=getint();
|
||||
putint(next);
|
||||
}
|
||||
else {
|
||||
next=getint();
|
||||
reverse(n-1);
|
||||
putint(next);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i=200;
|
||||
reverse(i);
|
||||
return 0;
|
||||
}
|
||||
73
testcases/functional_test/083_brainfk.sy
Normal file
73
testcases/functional_test/083_brainfk.sy
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
a brainfuck interpreter
|
||||
reference: https://gist.github.com/maxcountryman/1699708
|
||||
*/
|
||||
|
||||
// tape, input buffer, and read/write pointer
|
||||
const int TAPE_LEN = 65536, BUFFER_LEN = 32768;
|
||||
int tape[TAPE_LEN], program[BUFFER_LEN], ptr = 0;
|
||||
|
||||
// read the input program
|
||||
void read_program() {
|
||||
int i = 0, len = getint();
|
||||
while (i < len) {
|
||||
program[i] = getch();
|
||||
i = i + 1;
|
||||
}
|
||||
program[i] = 0;
|
||||
}
|
||||
|
||||
// interpret the input program
|
||||
void interpret(int input[]) {
|
||||
int cur_char, loop, i = 0;
|
||||
while (input[i]) {
|
||||
cur_char = input[i];
|
||||
if (cur_char == 62) {
|
||||
// '>'
|
||||
ptr = ptr + 1;
|
||||
}
|
||||
else if (cur_char == 60) {
|
||||
// '<'
|
||||
ptr = ptr - 1;
|
||||
}
|
||||
else if (cur_char == 43) {
|
||||
// '+'
|
||||
tape[ptr] = tape[ptr] + 1;
|
||||
}
|
||||
else if (cur_char == 45) {
|
||||
// '-'
|
||||
tape[ptr] = tape[ptr] - 1;
|
||||
}
|
||||
else if (cur_char == 46) {
|
||||
// '.'
|
||||
putch(tape[ptr]);
|
||||
}
|
||||
else if (cur_char == 44) {
|
||||
// ','
|
||||
tape[ptr] = getch();
|
||||
}
|
||||
else if (cur_char == 93 && tape[ptr]) {
|
||||
// ']'
|
||||
loop = 1;
|
||||
while (loop > 0) {
|
||||
i = i - 1;
|
||||
cur_char = input[i];
|
||||
if (cur_char == 91) {
|
||||
// '['
|
||||
loop = loop - 1;
|
||||
}
|
||||
else if (cur_char == 93) {
|
||||
// ']'
|
||||
loop = loop + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
read_program();
|
||||
interpret(program);
|
||||
return 0;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user