Skip to content

Instantly share code, notes, and snippets.

View ecnelises's full-sized avatar

Qiu Chaofan ecnelises

View GitHub Profile
@ecnelises
ecnelises / replace.c
Created October 24, 2015 13:32
C程序,把字符串source中出现的pattern替换成dest
#include <stdio.h>
#include <string.h>
const int max_length = 100;
int match_result[max_length];
char source[max_length * max_length];
char pattern[max_length];
char dest[max_length];
@ecnelises
ecnelises / qmemorypool.c
Last active March 25, 2018 08:28
用 C 写的类 deque 结构实现
/* qmemorypool.c
* By ecnelises
* 2015.11.10午
* 一个简易的类 deque 数据结构实现
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@ecnelises
ecnelises / expr.c
Created November 27, 2015 10:00
用C写的表达式求值程序(未考虑除错)
#include "expr.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#define ISPMO(x) (((x) == '+') || ((x) == '-'))
#define ISMDO(x) (((x) == '*') || ((x) == '/'))
#define ISO(x) (ISPMO(x) || ISMDO (x))
#define ISDIG(x) (isdigit(x) || ((x) == '.'))
@ecnelises
ecnelises / tokenizer.c
Last active November 30, 2015 16:38
从标准输入读取内容,并根据规则进行词法分析
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define currenttype (lexes[ntoken].type)
#define currentname (lexes[ntoken].name)
#define TOKEN_TYPE_INT 0x01
#define TOKEN_TYPE_DOUBLE 0x02
@ecnelises
ecnelises / qregex.c
Last active January 13, 2016 10:00
支持基本正则运算的正则引擎
/*
* regex.c
* Qiu Chaofan, 2016/1/12
*
* Regular expression engine.
*
* Features:
* Support matching for | * ? + . ()
* No error handling is considered yet.
*/
@ecnelises
ecnelises / 1.cpp
Created January 14, 2016 04:26
2016年同济C语言期末考试
#include <stdio.h>
#include <ctype.h>
int main(int argc, char const *argv[])
{
char ch, previous = '\0';
FILE *fp_in = fopen("in_1.txt", "r");
FILE *fp_out = fopen("1454001_1_out.txt", "w");
/*
@ecnelises
ecnelises / exam1.cpp
Created July 2, 2016 07:28
2016年同济C++期末考试上机题
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;
// Case-insensitive Compare
bool ci_comp(char c1, char c2)
@ecnelises
ecnelises / score_spider.rb
Last active August 14, 2018 18:09
从同济大学选课网站上爬取信息,输出绩点(支持统一认证登录)
require 'mechanize'
# xuanke.tongji.edu.cn 现采用统一认证登录,原登录方式不再使用
class NewGpaSpider
# 学期内所有课程
attr_reader :courses
def initialize(userid, password, term)
@agent = Mechanize.new
@ecnelises
ecnelises / soduku.rb
Created August 4, 2016 18:16
求解数独的程序
# 一行代表数独实际的一行,而不是一个九宫格
$soduku = [
[6, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 4, 1, 2, 9, 6, 0, 0, 0],
[0, 2, 5, 0, 0, 3, 6, 0, 4],
[0, 3, 0, 6, 7, 5, 8, 0, 0],
[8, 0, 6, 9, 0, 4, 5, 0, 2],
[4, 0, 9, 0, 0, 0, 0, 6, 0],
[7, 9, 0, 0, 6, 8, 0, 2, 0],
[0, 0, 8, 4, 5, 0, 3, 0, 1],
@ecnelises
ecnelises / Serialize.hpp
Created September 9, 2016 05:09
简易的C++二进制序列化类,模仿boost::serialization
// Serialize.hpp
// 简易的C++二进制序列化类,模仿boost::serialization
// 邱超凡 2016.9.9
#ifndef CPP_SERIALIZE_HPP
#define CPP_SERIALIZE_HPP
#include <fstream>
#include <algorithm>
#include <type_traits>