forked from NUDT-compiler/nudt-compiler-cpp
parent
d0a4c7d6d2
commit
69a6951f84
@ -0,0 +1 @@
|
||||
21
|
||||
@ -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];
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
9
|
||||
@ -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;
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
9
|
||||
@ -0,0 +1,7 @@
|
||||
//test add
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = -1;
|
||||
return a + b;
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
248
|
||||
@ -0,0 +1,7 @@
|
||||
//test sub
|
||||
const int a = 10;
|
||||
int main(){
|
||||
int b;
|
||||
b = 2;
|
||||
return b - a;
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
1 2 3 2
|
||||
0
|
||||
@ -0,0 +1,69 @@
|
||||
const int V = 4;
|
||||
const int space = 32;
|
||||
const int LF = 10;
|
||||
|
||||
void printSolution(int color[]) {
|
||||
int i = 0;
|
||||
while (i < V) {
|
||||
putint(color[i]);
|
||||
putch(space);
|
||||
i = i + 1;
|
||||
}
|
||||
putch(LF);
|
||||
}
|
||||
|
||||
void printMessage() {
|
||||
putch(78);putch(111);putch(116);
|
||||
putch(space);
|
||||
putch(101);putch(120);putch(105);putch(115);putch(116);
|
||||
}
|
||||
|
||||
int isSafe(int graph[][V], int color[]) {
|
||||
int i = 0;
|
||||
while (i < V) {
|
||||
int j = i + 1;
|
||||
while (j < V) {
|
||||
if (graph[i][j] && color[j] == color[i])
|
||||
return 0;
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int graphColoring(int graph[][V], int m, int i, int color[]) {
|
||||
if (i == V) {
|
||||
if (isSafe(graph, color)) {
|
||||
printSolution(color);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int j = 1;
|
||||
while (j <= m) {
|
||||
color[i] = j;
|
||||
if (graphColoring(graph, m, i + 1, color))
|
||||
return 1;
|
||||
color[i] = 0;
|
||||
j = j + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int graph[V][V] = {
|
||||
{0, 1, 1, 1},
|
||||
{1, 0, 1, 0},
|
||||
{1, 1, 0, 1},
|
||||
{1, 0, 1, 0}
|
||||
}, m = 3;
|
||||
int color[V], i = 0;
|
||||
while (i < V) {
|
||||
color[i] = 0;
|
||||
i = i + 1;
|
||||
}
|
||||
if (!graphColoring(graph, m, 0, color))
|
||||
printMessage();
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
4 4
|
||||
1 2 3 4
|
||||
5 6 7 8
|
||||
9 10 11 12
|
||||
13 14 15 16
|
||||
4 3
|
||||
9 5 1
|
||||
10 6 2
|
||||
11 7 3
|
||||
12 8 4
|
||||
@ -0,0 +1,5 @@
|
||||
110 70 30
|
||||
278 174 70
|
||||
446 278 110
|
||||
614 382 150
|
||||
0
|
||||
@ -0,0 +1,60 @@
|
||||
const int MAX_SIZE = 100;
|
||||
int a[MAX_SIZE][MAX_SIZE], b[MAX_SIZE][MAX_SIZE];
|
||||
int res[MAX_SIZE][MAX_SIZE];
|
||||
int n1, m1, n2, m2;
|
||||
void matrix_multiply() {
|
||||
int i = 0;
|
||||
while (i < m1) {
|
||||
int j = 0;
|
||||
while (j < n2) {
|
||||
int k = 0;
|
||||
while (k < n1) {
|
||||
res[i][j] = res[i][j] + a[i][k] * b[k][j];
|
||||
k = k + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
m1 = getint();
|
||||
n1 = getint();
|
||||
i = 0;
|
||||
while (i < m1) {
|
||||
j = 0;
|
||||
while (j < n1) {
|
||||
a[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
m2 = getint();
|
||||
n2 = getint();
|
||||
i = 0;
|
||||
while (i < m2) {
|
||||
j = 0;
|
||||
while (j < n2) {
|
||||
b[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
matrix_multiply();
|
||||
i = 0;
|
||||
while (i < m1) {
|
||||
j = 0;
|
||||
while (j < n2) {
|
||||
putint(res[i][j]);
|
||||
putch(32);
|
||||
j = j + 1;
|
||||
}
|
||||
putch(10);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
a
|
||||
46
|
||||
@ -0,0 +1 @@
|
||||
int main() { /* scope test */ putch(97); putch(10); int a = 1, putch = 0; { a = a + 2; int b = a + 3; b = b + 4; putch = putch + a + b; { b = b + 5; int main = b + 6; a = a + main; putch = putch + a + b + main; { b = b + a; int a = main + 7; a = a + 8; putch = putch + a + b + main; { b = b + a; int b = main + 9; a = a + 10; const int a = 11; b = b + 12; putch = putch + a + b + main; { main = main + b; int main = b + 13; main = main + a; putch = putch + a + b + main; } putch = putch - main; } putch = putch - b; } putch = putch - a; } } return putch % 77; }
|
||||
@ -0,0 +1 @@
|
||||
201
|
||||
@ -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;
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
24
|
||||
@ -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);
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
10
|
||||
0x1.999999999999ap-4 0x1.999999999999ap-3 0x1.3333333333333p-2 0x1.999999999999ap-2 0x1.0000000000000p-1
|
||||
0x1.3333333333333p-1 0x1.6666666666666p-1 0x1.999999999999ap-1 0x1.ccccccccccccdp-1 0x1.0000000000000p+0
|
||||
0x1.199999999999ap+0
|
||||
0x1.199999999999ap+1
|
||||
0x1.a666666666666p+1
|
||||
0x1.199999999999ap+2
|
||||
0x1.6000000000000p+2
|
||||
0x1.a666666666666p+2
|
||||
0x1.ecccccccccccdp+2
|
||||
0x1.199999999999ap+3
|
||||
0x1.3cccccccccccdp+3
|
||||
0x1.4333333333333p+3
|
||||
@ -0,0 +1,19 @@
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
0x1.e691e6p+1 3
|
||||
0x1.e691e6p+3 12
|
||||
0x1.11b21p+5 28
|
||||
0x1.e691e6p+5 50
|
||||
0x1.7c21fcp+6 78
|
||||
0x1.11b21p+7 113
|
||||
0x1.7487b2p+7 153
|
||||
0x1.e691e6p+7 201
|
||||
0x1.33e85p+8 254
|
||||
10: 0x1.333334p+0 0x1.333334p+1 0x1.ccccccp+1 0x1.333334p+2 0x1.8p+2 0x1.ccccccp+2 0x1.0cccccp+3 0x1.333334p+3 0x1.599998p+3 0x1p+0
|
||||
0
|
||||
@ -0,0 +1,98 @@
|
||||
// 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;
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
3
|
||||
Loading…
Reference in new issue