master
13388400053 2 years ago
parent d066802a8f
commit 7d41710582

@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -Wall -g -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -Wall -Wextra -Wno-unused -Wshadow -Werror -g -pedantic")
# include generated files in project environment
include_directories(${CMAKE_CURRENT_BINARY_DIR})

@ -109,7 +109,7 @@
* 线下: 线下检查只检查第三部分, 组长带组员到负责组长的助教处检查, 选做部分请找本次实验负责助教检查
* 迟交规定
* 迟交需要邮件通知助教:
* 邮箱: huangzq@mail.ustc.edu.cn
* 邮箱: xuchaijun@mail.ustc.edu.cn
* 邮件主题: PW6迟交-学号
* 内容: 包括迟交原因、最后版本commit ID、迟交时间等
* 关于抄袭和雷同

@ -10,6 +10,7 @@ set(SYSYF_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# include generated files in project environment
include_directories(${SYSYF_SOURCE_DIR}include)
include_directories(${SYSYF_SOURCE_DIR}include/SysYFIR)
add_subdirectory(${SYSYF_SOURCE_DIR}src/SysYFIR src/SysYFIR)

@ -15,24 +15,26 @@
#endif
#define CONST_INT(num) \
ConstantInt::get(num, module)
ConstantInt::create(num, module)
#define CONST_FP(num) \
ConstantFloat::get(num, module) // 得到常数值的表示,方便后面多次用到
ConstantFloat::create(num, module) // 得到常数值的表示,方便后面多次用到
using namespace SysYF::IR;
int main() {
auto module = new Module("SysY code"); // module name是什么无关紧要
auto builder = new IRStmtBuilder(nullptr, module);
Type *Int32Type = Type::get_int32_type(module);
auto module = Module::create("SysYF code"); // module name是什么无关紧要
auto builder = IRStmtBuilder::create(nullptr, module);
SysYF::Ptr<Type> Int32Type = Type::get_int32_type(module);
// 全局数组,num,x
auto *arrayType_num = ArrayType::get(Int32Type, 2);
auto *arrayType_x = ArrayType::get(Int32Type, 1);
auto zero_initializer = ConstantZero::get(Int32Type, module);
std::vector<Constant *> init_val;
auto arrayType_num = ArrayType::get(Int32Type, 2);
auto arrayType_x = ArrayType::get(Int32Type, 1);
auto zero_initializer = ConstantZero::create(Int32Type, module);
std::vector<SysYF::Ptr<Constant>> init_val;
init_val.push_back(CONST_INT(4));
init_val.push_back(CONST_INT(8));
auto num_initializer = ConstantArray::get(arrayType_num, init_val);
auto num_initializer = ConstantArray::create(arrayType_num, init_val);
auto num = GlobalVariable::create("num", module, arrayType_num, false, num_initializer);// 是否是常量定义,初始化常量(ConstantZero类)
auto x = GlobalVariable::create("x", module, arrayType_x, false, zero_initializer);// 参数解释: 名字name所属module全局变量类型type
@ -41,10 +43,10 @@ int main() {
// climbStairs函数
// 函数参数类型的vector
std::vector<Type *> Ints(1, Int32Type);
std::vector<SysYF::Ptr<Type>> Ints(1, Int32Type);
//通过返回值类型与参数类型列表得到函数类型
auto climbStairsFunTy = FunctionType::get(Int32Type, Ints);
auto climbStairsFunTy = FunctionType::create(Int32Type, Ints);
// 由函数类型得到函数
auto climbStairsFun = Function::create(climbStairsFunTy,
@ -58,7 +60,7 @@ int main() {
auto retAlloca = builder->create_alloca(Int32Type); // 在内存中分配返回值的位置
auto nAlloca = builder->create_alloca(Int32Type); // 在内存中分配参数n的位置
std::vector<Value *> args; // 获取climbStairs函数的形参,通过Function中的iterator
std::vector<SysYF::Ptr<Value>> args; // 获取climbStairs函数的形参,通过Function中的iterator
for (auto arg = climbStairsFun->arg_begin(); arg != climbStairsFun->arg_end(); arg++) {
args.push_back(*arg); // * 号运算符是从迭代器中取出迭代器当前指向的元素
}
@ -82,7 +84,7 @@ int main() {
builder->create_br(retBB); // br retBB
builder->set_insert_point(falseBB); // if false
auto *arrayType_dp = ArrayType::get(Int32Type, 10);
auto arrayType_dp = ArrayType::get(Int32Type, 10);
auto dpAlloca = builder->create_alloca(arrayType_dp);
auto dp0Gep = builder->create_gep(dpAlloca, {CONST_INT(0), CONST_INT(0)});
@ -147,7 +149,7 @@ int main() {
builder->create_ret(retLoad);
// main函数
auto mainFun = Function::create(FunctionType::get(Int32Type, {}),
auto mainFun = Function::create(FunctionType::create(Int32Type, {}),
"main", module);
bb = BasicBlock::create(module, "entry", mainFun);
// BasicBlock的名字在生成中无所谓,但是可以方便阅读
@ -189,6 +191,5 @@ int main() {
// 还有涉及到的C++语法,可以在gitlab上发issue提问或者向大家提供指导
// 对于这个例子里的代码风格/用法,如果有好的建议也欢迎提出!
std::cout << module->print();
delete module;
return 0;
}

@ -0,0 +1,65 @@
const int len = 200;
int V[len * len] = {};
int w[6] = {0,2,2,6,5,4};
int v[6] = {0,6,3,5,4,6};
int x[6];
int KnapSack(int n, int C)
{
int i, j;
i=1;
while(i<=n)
{
j=0;
while(j<C+1)
{
if (j<w[i])
V[i * len + j] = V[(i - 1) * len + j];
else
{
int tmp1=V[(i - 1) * len + j];
int tmp2=V[(i - 1) * len + j - w[i]] + v[i];
if(tmp1>tmp2)
{
V[i * len + j] = tmp1;
}
else
{
V[i * len + j] = tmp2;
}
}
j=j+1;
}
i=i+1;
}
j = C;
i=n;
while(i>=1)
{
if (V[i * len + j]>V[(i - 1) * len + j])
{
x[i] = 1;
j = j - w[i];
}
else
{
x[i] = 0;
}
i=i-1;
}
return V[n * len + C];
}
int main()
{
int s;
int n = 5;
int C=10;
s = KnapSack(n, C);
putint(s);
return 0;
}

@ -0,0 +1,2 @@
4010
++++++++[->++++++++<]>+++++++++.<+++++[->-----<]>---------.<++++++++[->++++++++<]>++++++.<++++++++[->--------<]>-------------.<+++++++[->+++++++<]>++.<+++++[->+++++<]>+++++++++.+++++.-----.--------.----.<++++[->++++<]>.<++++[->----<]>--------.<++++++++[->--------<]>-.<++++++[->++++++<]>++++.<+++++[->+++++<]>.<++++[->++++<]>+.+++.<+++[->---<]>----.+.<++++++++[->--------<]>---------.<++++++++[->++++++++<]>++++++.<+++[->+++<]>+++.---.--.<++++++++[->--------<]>-------------.<+++++++++[->+++++++++<]>+++.<+++[->---<]>---.---.<++++++++[->--------<]>-----.<++++++[->++++++<]>+.<+++++[->+++++<]>+++.<++++[->++++<]>++.+.<+++++++++[->---------<]>---.<++++++[->++++++<]>++++++.<++++++[->++++++<]>+++++++.-------.-----.++++++.+++.<+++++++++[->---------<]>-.<++++++[->++++++<]>++++.<+++++[->+++++<]>++++++++.--.+.<++++++++[->--------<]>--------.<+++++++[->+++++++<]>++.<++++[->++++<]>.+++++.+++++++..---.<++++++++[->--------<]>.<+++[->---<]>---.<++++++++[->++++++++<]>+.<+++[->+++<]>++++.<+++[->---<]>-.<++++++++[->--------<]>----.<++++++[->++++++<]>+++++.<+++++[->-----<]>---------.<++++++++[->++++++++<]>++++++.<++++++++[->--------<]>-------------.<++++++++[->++++++++<]>++++++++++++++.+.+++++.<+++++++++[->---------<]>---.<++++++++[->++++++++<]>+++++++++.+++++.++++++.<+++[->---<]>------.<+++[->+++<]>++++.<+++[->---<]>----.<+++[->+++<]>+++++.+.<+++[->---<]>------.-.<++++++++[->--------<]>----.<++++++++[->++++++++<]>+++++++++.+++++.<++++++++[->--------<]>--------------.<++++++++[->++++++++<]>+++++++++++++++.+++.<+++[->---<]>-----.+++++.+++++.<+++[->---<]>----.<++++[->++++<]>+.+++++++.<+++++++++[->---------<]>--------.<++++++++[->++++++++<]>++++++++.<+++[->+++<]>++++.--------.<+++[->---<]>---.<+++[->+++<]>++++.+++++.<++++++++[->--------<]>-----.<+++[->---<]>-----.<++++++[->++++++<]>+++++.<+++++[->+++++<]>++++.<++++++++[->--------<]>------.<+++++++++[->+++++++++<]>+++.<+++[->---<]>---.---.<+++[->+++<]>++++.<+++[->---<]>----.<++++++++[->--------<]>-----.<+++++++++[->+++++++++<]>++++++.<++++[->----<]>--.<+++[->+++<]>++++.<+++[->---<]>----.<++++++++[->--------<]>-----.<++++++++[->++++++++<]>+.<+++[->+++<]>++++.<++++++++[->--------<]>--------------.<++++++++[->++++++++<]>+.<+++[->+++<]>++.---.----.+++++++++.<++++++++[->--------<]>--.<+++[->---<]>---.<++++++++[->++++++++<]>+.<++++++++[->--------<]>-.<+++++++++[->+++++++++<]>+++.<+++[->---<]>--.++++.--------.<++++++++[->--------<]>-----.<+++++++++[->+++++++++<]>+++.--.<++++[->----<]>-.<++++[->++++<]>+++++.<++++[->----<]>-.+++++++..-------.<+++[->+++<]>++++.<++++++++[->--------<]>------.<+++[->---<]>---.<++++++++[->++++++++<]>+.<+++[->+++<]>++++.<++++++++[->--------<]>--------------.<++++++++[->++++++++<]>+++++++++++++++.+++++.<+++[->---<]>---.---.<+++[->+++<]>++++.+++++.--------.+++.------.--------.+.<+++[->+++<]>++++.<+++++++++[->---------<]>-.<++++++++[->++++++++<]>+++++++++++++++.+++.<+++++++++[->---------<]>-.<++++++++[->++++++++<]>+.<++++++++[->--------<]>-.<+++++++++[->+++++++++<]>++.++.-----.<+++[->---<]>--.<+++[->+++<]>++++.<+++[->---<]>-.---.<+++[->+++<]>++++.---.<++++++++[->--------<]>---------------.<++++++++[->++++++++<]>+.<+++[->+++<]>+++.++.-.-------.<++++++++[->--------<]>-------.<+++++++++[->+++++++++<]>++++++++.<+++[->---<]>-.++++++.<++++++++[->--------<]>---------.<+++[->---<]>---.<++++++++[->++++++++<]>++++++++++++++++.----.-------.----.<++++[->++++<]>++.<+++[->---<]>-----.<++++++++[->--------<]>-----.<++++++++[->++++++++<]>+++.<+++[->+++<]>+++.--.--------.<++++++++[->--------<]>-----.<+++++++++[->+++++++++<]>+++.-----.<++++++++[->--------<]>---------------.<++++++++[->++++++++<]>+++++++++++++.--------..<+++[->+++<]>++++++.<+++++++++[->---------<]>---.<++++++++[->++++++++<]>+++++++++++++.--------.<++++++++[->--------<]>----.-.<+++++++[->+++++++<]>+++.<++++[->++++<]>++++.-------.<++++[->++++<]>+++.<++++++++[->--------<]>-------------.<++++++++[->++++++++<]>++++++++++++.<+++++++++[->---------<]>--.<++++++++[->++++++++<]>+.<+++[->+++<]>++..<+++++++[->-------<]>-------------.<+++++[->-----<]>--------.---.<

@ -0,0 +1,2 @@
I'm Suzumiya Haruhi from the East Junior High School, and I'm not interested in ordinary humans. If there were an alien, a time traveller, an otherworlder or a superhero among you, please come to meet me! That's all.
0

@ -0,0 +1,75 @@
/*
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 cur_char, loop, i = 0;
while (program[i]) {
cur_char = program[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) {
if (tape[ptr]) {
// ']'
loop = 1;
while (loop > 0) {
i = i - 1;
cur_char = program[i];
if (cur_char == 91) {
// '['
loop = loop - 1;
}
else if (cur_char == 93) {
// ']'
loop = loop + 1;
}
}
}
}
i = i + 1;
}
}
int main() {
read_program();
interpret();
return 0;
}

@ -0,0 +1,6 @@
5
1+2* 3/4- 2 *411 ;
0 -1+10*1329000/ 22219 +99 ;
1199+ 98888/2227 %112-23;
* 2;
;

@ -0,0 +1,8 @@
-820
696
1220
panic!
-1
panic!
-1
0

@ -0,0 +1,175 @@
const int TOKEN_NUM = 0, TOKEN_OTHER = 1;
int last_char = 32, num, other;
int cur_token;
int oprs[256] = {}, ops[256] = {};
int next_char() {
last_char = getch();
return last_char;
}
int is_space(int c) {
if (c == 32) {
return 1;
}
else {
if (c == 10) return 1;
else return 0;
}
}
int is_num(int c) {
if (c >= 48) {
if (c <= 57)
return 1;
}
else {
return 0;
}
}
int next_token() {
while (is_space(last_char)) next_char();
if (is_num(last_char)) {
num = last_char - 48;
while (is_num(next_char())) {
num = num * 10 + last_char - 48;
}
cur_token = TOKEN_NUM;
}
else {
other = last_char;
next_char();
cur_token = TOKEN_OTHER;
}
return cur_token;
}
int panic() {
putch(112);
putch(97);
putch(110);
putch(105);
putch(99);
putch(33);
putch(10);
return -1;
}
int get_op_prec(int op) {
// +, -
if (op == 43) return 10;
if (op == 45) return 10;
// *, /, %
if (op == 42) return 20;
if (op == 47) return 20;
if (op == 37) return 20;
// other
return 0;
}
void stack_push(int flag, int v) {
if (flag == 0) {
oprs[0] = oprs[0] + 1;
oprs[oprs[0]] = v;
} else {
ops[0] = ops[0] + 1;
ops[ops[0]] = v;
}
}
int stack_pop(int flag) {
int last;
if (flag == 0) {
last = oprs[oprs[0]];
oprs[0] = oprs[0] - 1;
} else {
last = ops[ops[0]];
ops[0] = ops[0] - 1;
}
return last;
}
int stack_peek(int flag) {
int val;
if (flag == 0)
val = oprs[oprs[0]];
else
val = ops[ops[0]];
return val;
}
int stack_size(int flag) {
int val;
if (flag == 0)
val = oprs[0];
else
val = ops[0];
return val;
}
int eval_op(int op, int lhs, int rhs) {
// +
if (op == 43) return lhs + rhs;
// -
if (op == 45) return lhs - rhs;
// *
if (op == 42) return lhs * rhs;
// /
if (op == 47) return lhs / rhs;
// %
if (op == 37) return lhs % rhs;
// other
return 0;
}
int eval() {
// get the first value
if (cur_token != TOKEN_NUM) return panic();
stack_push(0, num);
next_token();
// evaluate
while (cur_token == TOKEN_OTHER) {
// get operator
int op = other;
if (get_op_prec(op) == 0) break;
next_token();
// handle operator
while (stack_size(1)) {
if (get_op_prec(stack_peek(1)) >= get_op_prec(op)) {
// evaluate the current operation
int cur_op = stack_pop(1);
int rhs = stack_pop(0), lhs = stack_pop(0);
stack_push(0, eval_op(cur_op, lhs, rhs));
} else {
break;
}
}
stack_push(1, op);
// get next expression
if (cur_token != TOKEN_NUM) return panic();
stack_push(0, num);
next_token();
}
// eat ';'
next_token();
// clear the operator stack
while (stack_size(1)) {
int cur_op = stack_pop(1);
int rhs = stack_pop(0), lhs = stack_pop(0);
stack_push(0, eval_op(cur_op, lhs, rhs));
}
return stack_peek(0);
}
int main() {
int count = getint();
getch();
next_token();
while (count) {
putint(eval());
putch(10);
count = count - 1;
}
return 0;
}

@ -0,0 +1,2 @@
abcabdbca
aababcabdabdababcabdbcadceadbcababcdcbaabsbda

@ -0,0 +1,75 @@
int dst[4096], src[4096];
int next[4096];
void get_next()
{
next[0] = -1;
int i = 0, j = -1;
while (dst[i]) {
if (j == -1 || dst[i] == dst[j]) {
j = j + 1;
i = i + 1;
next[i] = j;
}
else
j = next[j];
}
}
int KMP()
{
get_next();
int i = 0, j = 0;
while (src[j]) {
if (dst[i] == src[j]) {
i = i + 1;
j = j + 1;
if (dst[i] == 0) {
return j;
}
} else {
i = next[i];
if (i == -1) {
i = i + 1;
j = j + 1;
}
}
}
return -1;
}
int read_str(int flag)
{
if (flag == 0) {
int i = 0;
while (1) {
dst[i] = getch();
if (dst[i] == 10)
break;
i = i + 1;
}
dst[i] = 0;
return i;
} else {
int i = 0;
while (1) {
src[i] = getch();
if (src[i] == 10)
break;
i = i + 1;
}
src[i] = 0;
return i;
}
return 0;
}
int main()
{
read_str(0);
read_str(1);
putint(KMP());
putch(10);
return 0;
}

@ -0,0 +1,2 @@
02425294124166176216218-22282-34782142718170218357718485218672718700218877718865218842718825218832718815218822718825218832718815218822718805218
216

@ -0,0 +1,61 @@
const int N = 10000;
int long_array(int k) {
int a1[N];
int a2[N];
int a3[N];
int i = 0;
while (i < N) {
a1[i] = (i * i) % 10;
i = i + 1;
}
i = 0;
while (i < N) {
a2[i] = (a1[i] * a1[i]) % 10;
i = i + 1;
}
i = 0;
while (i < N) {
a3[i] = (a2[i] * a2[i]) % 100 + a1[i];
i = i + 1;
}
int ans = 0;
i = 0;
while (i < N) {
if (i < 10) {
ans = (ans + a3[i]) % 1333;
putint(ans);
}
else if (i < 20) {
int j = N / 2;
while (j < N) {
ans = ans + a3[i] - a1[j];
j = j + 1;
}
putint(ans);
}
else if (i < 30) {
int j = N / 2;
while (j < N) {
if (j > 2233) {
ans = ans + a2[i] - a1[j];
j = j + 1;
}
else {
ans = (ans + a1[i] + a3[j]) % 13333;
j = j + 2;
}
}
putint(ans);
}
else {
ans = (ans + a3[i] * k) % 99988;
}
i = i + 1;
}
return ans;
}
int main() {
return long_array(9);
}

@ -0,0 +1,108 @@
1
1 3 5 2 4
1 4 2 5 3
2 4 1 3 5
2 5 3 1 4
3 1 4 2 5
3 5 2 4 1
4 1 3 5 2
4 2 5 3 1
5 2 4 1 3
5 3 1 4 2
2 4 6 1 3 5
3 6 2 5 1 4
4 1 5 2 6 3
5 3 1 6 4 2
1 5 8 6 3 7 2 4
1 6 8 3 7 4 2 5
1 7 4 6 8 2 5 3
1 7 5 8 2 4 6 3
2 4 6 8 3 1 7 5
2 5 7 1 3 8 6 4
2 5 7 4 1 8 6 3
2 6 1 7 4 8 3 5
2 6 8 3 1 4 7 5
2 7 3 6 8 5 1 4
2 7 5 8 1 4 6 3
2 8 6 1 3 5 7 4
3 1 7 5 8 2 4 6
3 5 2 8 1 7 4 6
3 5 2 8 6 4 7 1
3 5 7 1 4 2 8 6
3 5 8 4 1 7 2 6
3 6 2 5 8 1 7 4
3 6 2 7 1 4 8 5
3 6 2 7 5 1 8 4
3 6 4 1 8 5 7 2
3 6 4 2 8 5 7 1
3 6 8 1 4 7 5 2
3 6 8 1 5 7 2 4
3 6 8 2 4 1 7 5
3 7 2 8 5 1 4 6
3 7 2 8 6 4 1 5
3 8 4 7 1 6 2 5
4 1 5 8 2 7 3 6
4 1 5 8 6 3 7 2
4 2 5 8 6 1 3 7
4 2 7 3 6 8 1 5
4 2 7 3 6 8 5 1
4 2 7 5 1 8 6 3
4 2 8 5 7 1 3 6
4 2 8 6 1 3 5 7
4 6 1 5 2 8 3 7
4 6 8 2 7 1 3 5
4 6 8 3 1 7 5 2
4 7 1 8 5 2 6 3
4 7 3 8 2 5 1 6
4 7 5 2 6 1 3 8
4 7 5 3 1 6 8 2
4 8 1 3 6 2 7 5
4 8 1 5 7 2 6 3
4 8 5 3 1 7 2 6
5 1 4 6 8 2 7 3
5 1 8 4 2 7 3 6
5 1 8 6 3 7 2 4
5 2 4 6 8 3 1 7
5 2 4 7 3 8 6 1
5 2 6 1 7 4 8 3
5 2 8 1 4 7 3 6
5 3 1 6 8 2 4 7
5 3 1 7 2 8 6 4
5 3 8 4 7 1 6 2
5 7 1 3 8 6 4 2
5 7 1 4 2 8 6 3
5 7 2 4 8 1 3 6
5 7 2 6 3 1 4 8
5 7 2 6 3 1 8 4
5 7 4 1 3 8 6 2
5 8 4 1 3 6 2 7
5 8 4 1 7 2 6 3
6 1 5 2 8 3 7 4
6 2 7 1 3 5 8 4
6 2 7 1 4 8 5 3
6 3 1 7 5 8 2 4
6 3 1 8 4 2 7 5
6 3 1 8 5 2 4 7
6 3 5 7 1 4 2 8
6 3 5 8 1 4 2 7
6 3 7 2 4 8 1 5
6 3 7 2 8 5 1 4
6 3 7 4 1 8 2 5
6 4 1 5 8 2 7 3
6 4 2 8 5 7 1 3
6 4 7 1 3 5 2 8
6 4 7 1 8 2 5 3
6 8 2 4 1 7 5 3
7 1 3 8 6 4 2 5
7 2 4 1 8 5 3 6
7 2 6 3 1 4 8 5
7 3 1 6 8 5 2 4
7 3 8 2 5 1 6 4
7 4 2 5 8 1 3 6
7 4 2 8 6 1 3 5
7 5 3 1 6 8 2 4
8 2 4 1 7 5 3 6
8 2 5 3 1 7 4 6
8 3 1 6 2 5 7 4
8 4 1 3 6 2 7 5
107

@ -0,0 +1,53 @@
int ans[50], sum = 0, n;
int row[50], line1[50], line2[100];
void printans()
{
sum = sum + 1;
int i = 1;
while (i <= n) {
putint(ans[i]);
if (i == n) {
putch(10);
return;
} else
putch(32);
i = i + 1;
}
}
void f(int step)
{
int i = 1;
while (i <= n) {
if (row[i] != 1) {
if (line1[step + i] == 0) {
if (line2[n + step - i] == 0) {
ans[step] = i;
if (step == n)
printans();
row[i] = 1;
line1[step + i] = 1;
line2[n + step - i] = 1;
f(step + 1);
row[i] = 0;
line1[step + i] = 0;
line2[n + step - i] = 0;
}
}
}
i = i + 1;
}
}
int main()
{
int N = getint();
while (N > 0) {
n = getint();
f(1);
N = N - 1;
}
return sum;
}

@ -0,0 +1,3 @@
1 2 3 4 5
6 7 8 9 10
11 12 13 14

@ -0,0 +1,96 @@
int func1(int x, int y, int z) {
if (z == 0) {
return x * y;
}
else {
return func1(x, y - z, 0);
}
}
int func2(int x, int y) {
if (y) {
return func2(x % y, 0);
}
else {
return x;
}
}
int func3(int x, int y) {
if (y == 0) {
return x + 1;
}
else {
return func3(x + y, 0);
}
}
int func4(int x, int y, int z) {
if (x) {
return y;
}
else {
return z;
}
}
int func5(int x) {
return -x;
}
int func6(int x, int y) {
if (x) {
if (y)
return 1;
}
else {
return 0;
}
}
int func7(int x) {
if (x == 0) {
return 1;
}
else {
return 0;
}
}
int main() {
int i1 = getint(), i2 = getint(), i3 = getint(), i4 = getint();
int arr[10];
int i = 0;
while (i < 10) {
arr[i] = getint();
i = i + 1;
}
int a = func1(
// this
func2(
// is
func1(
// comment
func3(func4(func5(func3(func2(func6(func7(i1), func5(i2)), i3),
// this
i4)),
// is
arr[0],
// function
func1(func2(func3(func4(func5(arr[1]),
// call
func6(arr[2], func7(arr[3])),
func2(arr[4], func7(arr[5]))),
arr[6]),
arr[7]),
func3(arr[8], func7(arr[9])), i1)),
func2(i2, func3(func7(i3), i4))),
arr[0], arr[1]),
arr[2]),
arr[3],
func3(func2(func1(func2(func3(arr[4], func5(arr[5])), func5(arr[6])),
arr[7], func7(arr[8])),
func5(arr[9])),
i1));
return a;
}

@ -0,0 +1,16 @@
int f(int a, int b) {
return a * b;
}
int g(int a, int b) {
return a % b;
}
int h(int a, int b) {
return f(f(2, g(a, b)), g(f(a, b), 4));
}
int main () {
putint(h(11, 3));
return 0;
}

@ -0,0 +1,10 @@
2 2
3 1
4 2
4 4
1 2
2 3
2 1
3 2
3 4
3 1

@ -0,0 +1,90 @@
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==0) {
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) {
if (array[loc + 1] != -1)
mmerge(loc, loc + 1);
}
if (b > 1) {
if (array[loc - 1] != -1)
mmerge(loc, loc - 1);
}
if (a < n) {
if (array[loc + n] != -1)
mmerge(loc, loc + n);
}
if (a > 1) {
if (array[loc - n] != -1)
mmerge(loc, loc - n);
}
if (array[0] != -1) {
if (array[k] != -1) {
if (findfa(0) == findfa(k)) {
flag = 1;
int tmp = i + 1;
putint(tmp);
putch(10);
}
}
}
}
i = i + 1;
}
if (flag == 0) {
putint(-1);
putch(10);
}
}
return 0;
}

@ -0,0 +1,26 @@
int k;
int main() {
k = 3389;
if (k < 10000) {
k = k + 1;
int k = 112;
while (k > 10) {
k = k - 88;
if (k < 1000) {
int g = 9;
{
int l = 11;
{
g = 10;
k = k - g;
int g = 11;
k = k + g + l;
}
}
}
}
putint(k);
}
return k;
}

@ -0,0 +1,19 @@
// Add is prior than equal and not equal
int main () {
int a;
int b;
int c;
a = 1;
b = 4;
c = 28;
int t;
if (c + a != b) {
t = c % -b;
putint(t);
}
if (b - c == a) {
t = c%b+b;
putint(t);
}
return 0;
}

@ -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;
}

@ -0,0 +1,17 @@
const int arr[5] = {1,3,4,2};
int a = 0;
int sum(int a, int b){
return a+b;
}
int main(){
int cnt = 0;
while (a < arr[a]) {
a = arr[a];
if (arr[a + arr[a] - 1] > arr[a] - 1.5) {
cnt = arr[cnt] + 1;
}
}
return sum(arr[a], -cnt);
}

@ -0,0 +1,14 @@
const int arr[5] = {1,3,4,2};
int a = 0;
int main(){
int cnt = 0;
while (a < arr[a]) {
a = arr[a];
if (arr[a + arr[a] - 1] > arr[a] - 1.5) {
continue;
cnt = arr[cnt] + 1;
}
}
return cnt;
}

@ -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;
}

@ -0,0 +1,2 @@
3102343761271952753654505476597868729361003112012671299112096683775968059149440439438030623917912792644636180
0

@ -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;
}

@ -0,0 +1,5 @@
int main(){
return 3;
int a = 1;
return a;
}

@ -0,0 +1,38 @@
int enc(int a)
{
if(a>25)
a=a+60;
else
{
a=a-15;
}
return a;
}
int dec(int a)
{
if (a>85)
a=a-59;
else
{
a=a+14;
}
return a;
}
int main()
{
int a;
a=400;
int res;
res=enc(a);
res=dec(res);
putint(res);
res = 10;
putch(res);
return 0;
}

@ -0,0 +1,23 @@
int x[1] = {1}, y[1] = {1};
int exgcd(int a,int b) {
if(b == 0) {
x[0] = 1;
y[0] = 0;
return a;
}
else {
int r = exgcd(b, a % b);
int t = x[0];
x[0] = y[0];
y[0] = (t - a / b * y[0]);
return r;
}
}
int main() {
int a = 7, b = 15;
exgcd(a, b);
x[0] = (x[0] % b + b) % b;
putint(x[0]);
return 0;
}

@ -0,0 +1,22 @@
int climbStairs(int n) {
if(n < 4)
return n;
int dp[10];
dp[0] = 0;
dp[1] = 1;
dp[2] = 2;
int i;
i = 3;
while(i<n+1){
dp[i] = dp[i-1] + dp[i-2];
i = i + 1;
}
return dp[n];
}
int main(){
int res;
int n;
n=5;
res = climbStairs(n);
return res;
}

@ -0,0 +1,12 @@
int a;
int inc_a(){
a = a + 1;
return a - 1;
}
int main(){
if (inc_a())
;
return a;
}

@ -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_());
}

@ -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());
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save