Archive for April, 2009

April 28, 2009

POJ 的一道题,算法很简单:

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
#include <string>
#include <iostream>
using namespace std;
 
int main()
{
    int n;
    char b2h[17] = "0123456789ABCDEF";
    int flag[4] = {1,2,4,8};
    cin>>n;
    while (n--)
    {
        string s;cin>>s;
        int len = s.length();
        int mod = len%4;
        int num = 0;
        for (int i=mod;i>0;i--)
        {
            if (s[mod-i]=='1')
            {
                num += flag[i-1];
            }
        }
        if (mod)
            cout<<b2h[num];
        for (int i=mod;i<len;i+=4)
        {
            num = 0;
            for (int j=0;j<4;j++)
            {
                if (s[i+j]=='1')
                {
                    num += flag[3-j];
                }
            }
            cout<<b2h[num];
        }
        cout<<endl;
    }
    return 0;
}
Tags: . 34 views

This phenomenon merely happens when your windows had been shutdown innormally or the USB device is unmounted innormally. To fix this problem, just do as the ‘Details’ tell you:

sudo mount -t ntfs-3g /dev/sdb1 /media/yourvolume -o force

As the command complishes, you will make it when try mount the very volume another time. Good luck!

Tags: ,. 49 views
April 27, 2009
  • 尽量减小变量的作用域
    • 全局变量
    • 类 public 变量
    • protect 变量
    • 文件级变量
    • private 变量
    • 函数级 static 变量
    • 函数级临时变量
    • 语句级临时变量
  • 尽量减少 free variable
  • 减少使用复杂的逻辑语句。
  • 只有在需要的时候才定义类,函数或者变量。或者说不要有从来都不用的类, 函数或者变量。
  • 使用统一风格的缩进格式。
  • 聪明的数据,傻瓜的代码
  • 深刻理解const 语句,尽量使用 const 语句。
  • 如果能够使用引用,就不要使用指针
  • 尽量用 private 代替 protect 语句。
  • 类继承 不要超过 3 级以上
  • 尽量减少类的个数。
  • 区别对待 BUG
    • 功能限制不是 BUG , BUG 是正确输入的产成了错误的输入。
    • 如果输入的数据的是错误的,那么程序不应该产生输 出,而是给出错误处理。 尽量不使用没有 else 的 if 语句。尽量不使用没有 default 的 switch 语句。 如果 else 的部分什么都不干,那么给出空语句。
  • 关于拷贝构造函数和等号的操作符重载
    • 尽量建立自己的拷贝构造函数,改变默认的拷贝构造 函数。拷贝构造函数的内容一般是 assert(false) 语句。意思是说不可以调用拷贝构造函数,也就是这 个类的对象不能作为函数的参数传递,也不能用 aClass obj(oldobj) 的形式创建对象。只有确定需 要以上功能的时候,才编写拷贝构造函数。等号的操 作符重载类似。
  • 尽量多的使用 assert 函数。
  • 用对象组合代替类继承 。
Tags: . 10 views

运行期(runtime)判断
下面的程序可以在运行期判断 endianess:

int IsBigEndian (void)
{
        static const int v =1;
        return *(char*)&v?0:1;
}
Tags: ,. 19 views
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
# 配置部分
# 下面的变量可以在shell 的环境变量里面指定。
# 也可以象下面这样在 Makefile 里面指定。
# CC=gcc                      # 编译器
# CFLAGS=-Wall -Werror -g     # 编译器参数
# LD=gcc                      # 连接器参数
# LDFLAGS= $(LIBS)  -lpthread # 连接器参数
# DEPENDFLAG=-MM              # 生成依赖关系文件的参数
# INCLUDES=-Idir1 -Idir2      # 指明包含外部头文件的目录
# LIBS=-la -lb -lc            # 指明引用外部的库文件
CFLAGS:=$(CFLAGS) $(INCLUDES)
LDFLAGS:=$(LDFLAGS) $(LIBS)
 
#指明项目中,包含源程序的所有的子目录。
SRCDIRS=.
#指明最终生成的可执行文件的名称
PROGRAMS=test.exe
 
#下面的部分一般不用改动
 
#从所有子目录中得到源代码的列表
SRCS=$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c))
 
#得到源代码对应的目标文件的列表
OBJS=$(SRCS:.c=.o)
 
#得到源代码对应的依赖关系文件的列表
#依赖关系文件就是一个目标文件依赖于
#哪些头文件和源程序,依赖关系是自动
#生成的,并且用 include 语句包含在
#Makefile 中。
DEPENDS=$(SRCS:.c=.d)
 
#指明默认目标是生成最终可执行文件。
all: $(PROGRAM)
 
#生成依赖关系文件
%.d:%.c
        $(CC) $(DEPENDFLAG) $(CFLAGS)  $< |\
        sed "s?\\(.*\\):?$(basename $<).o $(basename $<).d :?g" \
        > $@ || $(RM) $@
 
$(PROGRAMS): $(OBJS)
        $(CC) $(LDFLAGS) -o $@ $(filter %.o ,$+)
 
# 包含入依赖关系文件
include $(DEPENDS)
 
# 删除生成的中间文件
clean:
        rm $(OBJS) $(DEPENDS) $(PROGRAMS)
Tags: ,. 49 views

剪切复制文本区域

1. 把光标移动到区域的首字符
2. C-@ 设置标记
3. 把光标移动到区域后的第一个字符
4. C-w 剪切,M-w 复制
5. C-y 粘贴

Tags: ,. 29 views

Description

A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., xm > another sequence Z = < z1, z2, ..., zk > is a subsequence of X if there exists a strictly increasing sequence < i1, i2, ..., ik > of indices of X such that for all j = 1,2,…,k, xij = zj. For example, Z = < a, b, f, c > is a subsequence of X = < a, b, c, f, b, c > with index sequence < 1, 2, 4, 6 >. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.

Tags: . 26 views
April 25, 2009

对机器配置的要求:
需要一台电脑做服务器,配置并不需要太高,主流配置甚至以下的机器都可以,因为我们用linux系统下的开源软件vsftpd做服务器端。甚至并不需要显示器,在配置系统时可临时借用其他机器的显示器,以后的管理工作可通过SSH来进行。但网络是必须的,硬盘也还是大一点的好。因此,当你有一台淘汰下来的闲置的低配机器时,可考虑发挥它的余热,用来做ftp,分享一些电影、音乐、软件等资源。

Tags: ,. 46 views
$ sudo apt-get install apache2

虽然暂时我还用不到mysql,但以后就能用到了。毕竟apache+python(/perl/php)+mysql是最强大的web服务组合。安装命令:

$ sudo apt-get install mysql-server python-mysqldb libapache2-mod-python

安装完成后,在浏览器中访问http://www.dutor.net/或者http://127.0.0.1/ 即可看到 It works 字样,说明apache已经初步安装成功。

Tags: ,. 9 views

Introduction

A good way to get into an argument with a computer programmer is to attempt to explain why the language they are using is not as good as the one you are using. Most of the programmers I know are positively religious over their Operating System (see my other article), their development language and finally their text editor.

Tags: . 10 views
Page 2 of 41234