stat函数和stat命令

linux文件里的【inode = index node】解释:要理解inode必须了解磁盘和【目录项】,inode实际是连接【目录项】和磁盘的中间物质。

  • 图里的大圈代表硬件的磁盘,里面的小圈代表某个文件存储在磁盘上了。

  • 【inode = index node】的node(承载node信息的结构体是:stat,stat的定义在后面 )里面有:

    • 文件大小
    • 文件的最后修改时间
    • 文件的所属用户
    • 文件的权限
    • 硬链接计数(ls -l 显示出来的数字)
    • 块位置:指定文件存储在磁盘的具体位置。
  • 下图中的hello是个普通文件,hello.hard是hello的硬链接

  • 文件夹里放的就是每个文件的【目录项】如下图,【目录项】里有:

    • 文件名
    • 该目录项的大小
    • 文件的类型
    • inode

  • 如何查看文件的【inode】呢?使用【-i】选项

    1. ls -li 文件名

    执行结果:

    1. ys@ys-VirtualBox:~/lianxi1$ ls -li hello hello.hard
    2. 3801352 -rw-rw-r-- 2 ys ys 0 4 24 11:01 hello
    3. 3801352 -rw-rw-r-- 2 ys ys 0 4 24 11:01 hello.hard

    发现hello和hello.hard的inode(3801352)是相同的,也就说明了,只在磁盘上存了一份。

  • 如何查看目录项呢?用emacs或者vim打开目录(lianxi1),截图如下。但是看不到文件的【inode】。

1,stat函数:取得指定文件的文件属性,文件属性存储在结构体stat里。

  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <unistd.h>
  4. int stat(const char *pathname, struct stat *statbuf);
  5. int fstat(int fd, struct stat *statbuf);
  6. int lstat(const char *pathname, struct stat *statbuf);

struct stat 结构体:

  1. struct stat {
  2. dev_t st_dev; /* ID of device containing file */
  3. ino_t st_ino; /* Inode number */
  4. mode_t st_mode; /* File type and mode */
  5. nlink_t st_nlink; /* Number of hard links */
  6. uid_t st_uid; /* User ID of owner */
  7. gid_t st_gid; /* Group ID of owner */
  8. dev_t st_rdev; /* Device ID (if special file) */
  9. off_t st_size; /* Total size, in bytes */
  10. blksize_t st_blksize; /* Block size for filesystem I/O */
  11. blkcnt_t st_blocks; /* Number of 512B blocks allocated */
  12. /* Since Linux 2.6, the kernel supports nanosecond
  13. precision for the following timestamp fields.
  14. For the details before Linux 2.6, see NOTES. */
  15. struct timespec st_atim; /* Time of last access */
  16. struct timespec st_mtim; /* Time of last modification */
  17. struct timespec st_ctim; /* Time of last status change */
  18. #define st_atime st_atim.tv_sec /* Backward compatibility */
  19. #define st_mtime st_mtim.tv_sec
  20. #define st_ctime st_ctim.tv_sec
  21. };
  • st_dev:设备ID,不太常用

  • st_ino:【inode】,【inode】是啥?不知道就看上面关于【inode】的解释

  • st_mode:文件的类型和权限,共16位,如下图。

    • 0-11位控制文件的权限

    • 12-15位控制文件的类型

    0-2比特位:其他用户权限

    3-5比特位:组用户权限

    6-8比特位:本用户权限

    9-11比特位:特殊权限

    12-15比特位:文件类型(因为文件类型只有7中,所以用12-14位就够了

文件类型的宏如下(下面的数字是8进制):

  • S_IFSOCK 0140000 socket
  • S_IFLNK 0120000 symbolic link(软连接)
  • S_IFREG 0100000 regular file(普通文件)
  • S_IFBLK 0060000 block device(块设备文件)
  • S_IFDIR 0040000 directory(目录)
  • S_IFCHR 0020000 character device(字符设备文件)
  • S_IFIFO 0010000 FIFO(管道)
  1. 判断文件类型的函数,返回truefalse
  2. S_ISREG(stat.st_mode) is it a regular file?
  3. S_ISDIR(stat.st_mode) directory?
  4. S_ISCHR(stat.st_mode) character device?
  5. S_ISBLK(stat.st_mode) block device?
  6. S_ISFIFO(m) FIFO (named pipe)?
  7. S_ISLNK(stat.st_mode) symbolic link? (Not in POSIX.1-1996.)
  8. S_ISSOCK(stat.st_mode) socket? (Not in POSIX.1-1996.)

文件权限的宏如下:

  1. S_ISUID 04000 set-user-ID bit
  2. S_ISGID 02000 set-group-ID bit (see below)
  3. S_ISVTX 01000 sticky bit (see below)
  4. S_IRWXU 00700 owner has read, write, and execute permission
  5. S_IRUSR 00400 owner has read permission
  6. S_IWUSR 00200 owner has write permission
  7. S_IXUSR 00100 owner has execute permission
  8. S_IRWXG 00070 group has read, write, and execute permission
  9. S_IRGRP 00040 group has read permission
  10. S_IWGRP 00020 group has write permission
  11. S_IXGRP 00010 group has execute permission
  12. S_IRWXO 00007 others (not in group) have read, write, and
  13. execute permission
  14. S_IROTH 00004 others have read permission
  15. S_IWOTH 00002 others have write permission
  16. S_IXOTH 00001 others have execute permission
  • st_nlink:硬连接计数

  • st_uid:这个文件所属用户的ID

  • st_gid:这个文件所属用户的组ID

  • st_rdev:特殊设备的ID,不太常用

  • st_size:文件的大小

  • st_blksize:不明是干啥的

  • st_blocks:不明是干啥的

  • struct timespec st_atim:最后访问的时间

  • struct timespec st_mtim:最后修改的时间

  • struct timespec st_ctim:最后状态改变的时间

    1. struct timespec {
    2. __kernel_time_t tv_sec; /* seconds */当前时间到1970.1.1 00:00:00的秒数
    3. long tv_nsec; /* nanoseconds *//纳秒数(不知道从哪到哪的)
    4. };
    5. 1s = 1000ms 毫秒
    6. 1ms 毫秒 = 1000us 微秒
    7. 1us 微秒 = 1000ns 纳秒

pathname:文件名

返回值:0代表成功;-1代表失败,并设置error

例子:statbuf是结构体stat,可以看出来st_mode是个10进制的数字。

  • st_mode

    用gdb显示st_mode,发现返回的st_mode是个10进制的数字,用gdb的【p/o】(o代表用8进制表示)命令把10进制的33204转换成了8进制的【0100664】,第一个0代笔是8进制,后三位的【100】代表文件类型,从上面的说明可以看出来【100】代表普通文件,最后三位的【664】代表这个文件的权限(本用户:rw-,组用户:rw-,其他用户:r--)。所以从st_mode里就可以得知文件的类型和权限设置(只使用了16个比特位,真的好节省空间,牛逼!)

  • st_uid

  • st_gid

    发现st_uid和st_gid是1000,但这个1000怎么和用户对应上呢,查看/etc/passwd文件,发现用于ys的uid和gid都是1000,所以就对应上了。

stat命令,是stat函数对应,执行结果如下:

  1. ys@ys-VirtualBox:~/lianxi1$ stat hello
  2. File: hello
  3. Size: 11 Blocks: 8 IO Block: 4096 regular file
  4. Device: 801h/2049d Inode: 3801352 Links: 2
  5. Access: (0764/-rwxrw-r--) Uid: ( 1000/ ys) Gid: ( 1000/ ys)
  6. Access: 2019-04-24 17:02:39.199461489 +0800
  7. Modify: 2019-04-24 16:54:16.407461489 +0800
  8. Change: 2019-04-24 17:03:44.927461489 +0800

2,getpwuid函数:返回/etc/passwd文件里指定uid的行,把这一行的信息放入结构体passwd中。虽然返回值是指针,但不需要调用free函数。

  1. #include <sys/types.h>
  2. #include <pwd.h>
  3. struct passwd *getpwnam(const char *name);
  4. struct passwd *getpwuid(uid_t uid);
  5. struct passwd {
  6. char *pw_name; /* username */
  7. char *pw_passwd; /* user password */
  8. uid_t pw_uid; /* user ID */
  9. gid_t pw_gid; /* group ID */
  10. char *pw_gecos; /* user information */
  11. char *pw_dir; /* home directory */
  12. char *pw_shell; /* shell program */
  13. };

3,getgrgid函数:返回/etc/group文件里指定gid的行,把这一行的信息放入结构体group中。虽然返回值是指针,但不需要调用free函数。

  1. #include <sys/types.h>
  2. #include <grp.h>
  3. struct group *getgrnam(const char *name);
  4. struct group *getgrgid(gid_t gid);
  5. struct group {
  6. char *gr_name; /* group name */
  7. char *gr_passwd; /* group password */
  8. gid_t gr_gid; /* group ID */
  9. char **gr_mem; /* NULL-terminated array of pointers
  10. to names of group members */
  11. };

4,localtime函数:传入从stat函数里得到的st_mtim.tv_sec(当前时间到1970.1.1 00:00:00的秒数),得到结构体tm。虽然返回值是指针,但不需要调用free函数。

  1. #include <time.h>
  2. struct tm *localtime(const time_t *timep);
  3. struct tm {
  4. int tm_sec; /* Seconds (0-60) */
  5. int tm_min; /* Minutes (0-59) */
  6. int tm_hour; /* Hours (0-23) */
  7. int tm_mday; /* Day of the month (1-31) */
  8. int tm_mon; /* Month (0-11) */
  9. int tm_year; /* Year - 1900 */
  10. int tm_wday; /* Day of the week (0-6, Sunday = 0) */
  11. int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
  12. int tm_isdst; /* Daylight saving time */
  13. };

5,lstat函数:stat碰到软链接,会追述到源文件,穿透;lstat并不会穿透。

例子:模仿ls -l 文件

  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <pwd.h>//getpwuid
  7. #include <stdlib.h>
  8. #include <time.h>//localtime
  9. #include <grp.h>//getgrgid
  10. int main(int argc, char* argv[]){
  11. struct stat sbuf;
  12. //stat(argv[1], &sbuf);
  13. lstat(argv[1], &sbuf);
  14. char str[11] = {0};
  15. memset(str, '-', (sizeof str - 1));
  16. //文件类型
  17. if(S_ISREG(sbuf.st_mode)) str[0] = '-';
  18. if(S_ISDIR(sbuf.st_mode)) str[0] = 'd';
  19. if(S_ISCHR(sbuf.st_mode)) str[0] = 'c';
  20. if(S_ISBLK(sbuf.st_mode)) str[0] = 'b';
  21. if(S_ISFIFO(sbuf.st_mode)) str[0] = 'p';
  22. if(S_ISLNK(sbuf.st_mode)) str[0] = 'l';
  23. if(S_ISSOCK(sbuf.st_mode)) str[0] = 's';
  24. //本用户的文件权限
  25. if(sbuf.st_mode & S_IRUSR) str[1] = 'r';
  26. if(sbuf.st_mode & S_IWUSR) str[2] = 'w';
  27. if(sbuf.st_mode & S_IXUSR) str[3] = 'x';
  28. //本用户的组的文件权限
  29. if(sbuf.st_mode & S_IRGRP) str[4] = 'r';
  30. if(sbuf.st_mode & S_IWGRP) str[5] = 'w';
  31. if(sbuf.st_mode & S_IXGRP) str[6] = 'x';
  32. //其他用户的文件权限
  33. if(sbuf.st_mode & S_IROTH) str[7] = 'r';
  34. if(sbuf.st_mode & S_IWOTH) str[8] = 'w';
  35. if(sbuf.st_mode & S_IXOTH) str[9] = 'x';
  36. char ymd[20] = {0};
  37. //取得日期和时间
  38. struct tm* tm = localtime(&sbuf.st_atim.tv_sec);
  39. sprintf(ymd, "%2d月 %2d %02d:%02d", tm->tm_mon + 1, tm->tm_mday,
  40. tm->tm_hour + 1,tm->tm_sec);
  41. //-rw-r--r-- 1 ys ys 134 4月 25 09:21 st2.c
  42. printf("%s %ld %s %s %ld %s %s\n", str, sbuf.st_nlink,
  43. getpwuid(sbuf.st_uid)->pw_name, getgrgid(sbuf.st_gid)->gr_name,
  44. sbuf.st_size, ymd, argv[1]);
  45. return 0;
  46. }

6,access函数:判断调用程序的用户对于指定文件的权限(可读?可写?可执行?)

  1. #include <unistd.h>
  2. int access(const char *pathname, int mode);
  • pathname:文件
  • mode
    • R_OK:可读?
    • W_OK:可写?
    • X_OK:可执行?
    • F_OK:文件存在?
  • 返回值
    • 查询的权限存在或者文件存在:返回0。
    • 查询的权限不存在或者文件不存在:返回-1。

例子:

  1. #include <stdio.h>
  2. #include <unistd.h>//access
  3. int main(int argc, char* argv[]){
  4. if(access(argv[1], R_OK) == 0)
  5. printf("read ok\n");
  6. if(access(argv[1], W_OK) == 0)
  7. printf("write ok\n");
  8. if(access(argv[1], X_OK) == 0)
  9. printf("exe ok\n");
  10. if(access(argv[1], F_OK) == 0)
  11. printf("exists\n");
  12. }
  • 先用ls -l 查看/usr/include/time.h文件的权限,结果如下

    1. ys@ys-VirtualBox:~/lianxi$ ls -l /usr/include/time.h
    2. -rw-r--r-- 1 root root 10360 4 17 2018 /usr/include/time.h
  • 用ys用户执行例子程序,查看/usr/include/time.h文件,结果如下。因为time.h是属于root用户的,对于其他用户来说是[r--],所以得出下面的结果。

    1. ys@ys-VirtualBox:~/lianxi$ ./ac /usr/include/time.h
    2. read ok
    3. exists
  • 还是用ys用户执行,但是加上sudo,结果如下。发现结果和root用户相同。因为加了sudo,就编程了root用户。

    1. ys@ys-VirtualBox:~/lianxi$ sudo ./ac /usr/include/time.h
    2. [sudo] password for ys:
    3. read ok
    4. write ok
    5. exists

7,truncate函数:截断文件和扩展文件的大小

  1. #include <unistd.h>
  2. #include <sys/types.h>
  3. int truncate(const char *path, off_t length);
  • path:文件
  • length:
    • length大于原来文件的大小,则扩展文件的大小至length
    • length小于原来文件的大小,则截断文件的大小至length

8,link函数:创建硬链接

  1. #include <unistd.h>
  2. int link(const char *oldpath, const char *newpath);

返回值:成功返回0,失败返回-1,并设置errno。

9,symlink函数:创建软链接

  1. #include <unistd.h>
  2. int symlink(const char *target, const char *linkpath);

返回值:成功返回0,失败返回-1,并设置errno。

10,readlink函数:找到软链接对应的实际文件,把文件的名字放入buf里。注意:硬链接不行。

  1. #include <unistd.h>
  2. ssize_t readlink(const char *pathname, char *buf, size_t bufsiz);

返回值:成功返回写入buf的字节数,失败返回-1,并设置errno。

11,unlink函数:删除软硬链接,也可以删除文件。

  1. #include <unistd.h>
  2. int unlink(const char *pathname);

返回值:成功返回0,失败返回-1,并设置errno。

有个特殊用法:下面的open代码想要创建hello文件,然后直接用unlink删除,但是能写入成功,ret是大于0的,程序执行完,发现没有做成hello文件。

结论:当执行unlink后,计数为0后,但,发现别的进程还引用这个文件,这个时间点,unlink不会删除这个文件,等这个进程结束后,再删除,所以下面的write代码能够写入成功。

利用这个特点可以实现:在线观看视频时,实际是把视频文件下载到了本地(然后代码里,使用unlink),看完后视频文件的计数为0,就自动删除了,不怕视频被泄露出去。

  1. #include <unistd.h>
  2. #include <sys/types.h>
  3. #include <stdio.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. int main(){
  7. int fd = open("hello", O_WRONLY | O_CREAT, 0666);
  8. unlink("hello");
  9. int ret = write(fd, "aaa", 4);
  10. if(ret > 0){
  11. printf("write OK\n");
  12. }
  13. }

12,chown函数:改变文件的所属用户和组

  1. #include <unistd.h>
  2. int chown(const char *pathname, uid_t owner, gid_t group);
  • pathname:文件
  • owner:用户ID(数字的)/etc/passwd
  • group:组ID(数字的)/etc/group
  • 返回值:0成功,-1失败。

13,rename函数:重命名

  1. #include <stdio.h>
  2. int rename(const char *oldpath, const char *newpath);
  • oldpath :原来的文件名后者目录
  • newpath:新的文件名后者目录
  • 返回值:0成功,-1失败。

14,getcwd函数:获得当前工作的目录

  1. #include <unistd.h>
  2. char *getcwd(char *buf, size_t size);
  • buf:当前工作的目录
  • size:缓冲区大小
  • 返回值:
    • 成功返回当前工作的目录
    • 失败返回NULL

15,chdir函数:改变进程的工作目录

  1. #include <unistd.h>
  2. int chdir(const char *path);
  • path:目标工作目录
  • 返回值:0成功,-1失败

16,mkdir函数:创建目录

  1. #include <sys/stat.h>
  2. #include <sys/types.h>
  3. int mkdir(const char *pathname, mode_t mode);
  • pathname:目标工作目录
  • mode:mode & ~umask & 0777 。注意,如果没有x权限,则无法cd进入这个目录。
  • 返回值:0成功,-1失败

17,rmdir函数:删除目录,目录必须是空目录,也就是里面没有任何文件。

  1. #include <unistd.h>
  2. int rmdir(const char *pathname);

18,opendir函数:打开目录

  1. #include <sys/types.h>
  2. #include <dirent.h>
  3. DIR *opendir(const char *name);
  • name:目录名
  • 返回值:a pointer to the directory stream

19,readdir函数:读目录

  1. #include <dirent.h>
  2. struct dirent *readdir(DIR *dirp);
  3. struct dirent {
  4. ino_t d_ino; /* Inode number */
  5. off_t d_off; /* Not an offset; see below */
  6. unsigned short d_reclen; /* Length of this record */
  7. unsigned char d_type; /* Type of file; not supported
  8. by all filesystem types */
  9. char d_name[256]; /* Null-terminated filename */
  10. };
  • dirp:opendir函数的返回值
  • 返回值:结构体dirent,可以理解成最上面说的【目录项】
    • NULL代表读到末尾或者有错误
    • NULL以外代表目录项的内容

20,closedir函数:关闭目录

  1. #include <sys/types.h>
  2. #include <dirent.h>
  3. int closedir(DIR *dirp);
  • dirp:opendir函数的返回值

21,strerron函数:打印出errno对应的文字信息。

  1. #include <string.h>
  2. char *strerror(int errnum);
  • errnum的宏放在文件:/usr/include/asm-generic/errno.h

例子:

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <asm-generic/errno.h>//EDEADLK
  4. int main(){
  5. char* buf = strerror(EDEADLK);
  6. printf("%s\n", buf);//Resource deadlock avoided
  7. }

22,dup和dup2函数:文件描述符的重定向

  1. #include <unistd.h>
  2. int dup(int oldfd);
  3. int dup2(int oldfd, int newfd);
  • dup:和open类似,先打开一个新的文件描述符,让新的文件描述符也指向:oldfd指向的地方。

    • 成功返回新打开的文件描述符;失败返回-1.
  • dup2:
    • 先消除newfd的指向
    • 再让newfd指向oldfd指向的地方
    • 成功返回newfd;失败返回-1.

例子:调用printf2次,第一次printf把内容写到文件;第二次printf把内容打印到屏幕。

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. int main(){
  7. int oldfd = dup(STDOUT_FILENO);
  8. int fd = open("www", O_WRONLY | O_CREAT, 0666);
  9. dup2(fd, STDOUT_FILENO);
  10. printf("aaaa\n");
  11. fflush(stdout);
  12. int ret = dup2(oldfd, STDOUT_FILENO);
  13. //int ret = dup2(oldfd, 6);
  14. //perror("dup2:");
  15. printf("reg:%d\n", ret);
  16. printf("aaaa\n");
  17. close(fd);
  18. }

c/c++ 学习互助QQ群:877684253

本人微信:xiaoshitou5854

Linux stat函数和stat命令的更多相关文章

  1. linux shell 中的sleep命令

    开始还以为是这样的语法: sleep(1), 后面发现是: linux shell 中的sleep命令 分类: LINUX 在有的shell(比如linux中的bash)中sleep还支持睡眠(分,小 ...

  2. linux运维中的命令梳理(四)

    ----------管理命令---------- ps命令:查看进程 要对系统中进程进行监测控制,查看状态,内存,CPU的使用情况,使用命令:/bin/ps (1) ps :是显示瞬间进程的状态,并不 ...

  3. linux 查看服务器性能常用命令

    一.top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器   下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来 ...

  4. Linux基础01 学会使用命令帮助

    Linux基础01 学会使用命令帮助 概述 在linux终端,面对命令不知道怎么用,或不记得命令的拼写及参数时,我们需要求助于系统的帮助文档:linux系统内置的帮助文档很详细,通常能解决我们的问题, ...

  5. linux type 命令和Linux的五个查找命令

    type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keyword 关键字,Shell保留字 function 函数,Shell函数 builtin 内建命令,Shel ...

  6. Linux最常用的基础命令

    Linux最常用的基础命令个人总结 计算机基础知识: 32bit和64bit系统的区别.系统运行机制 32bit=内存的最大寻址空间是2**32,也就是说最大只能使用4GB的内存64bit=内存的最大 ...

  7. Linux学习之文本处理命令(五)

    ---恢复内容开始--- Linux 系统之文本处理命令 (一)基于关键字搜索 (二)基于列处理文本 (三)文本统计 (四)文本排序 (五)删除重复行 (六)文本比较 (七)处理文本内容 (八)搜索替 ...

  8. 查看Linux下系统资源占用常用命令

    一 top命令 1.作用top命令用来显示执行中的程序进程,使用权限是所有用户. 2.格式top [-] [d delay] [q] [c] [S] [s] [i] [n] 3.主要参数d:指定更新的 ...

  9. Linux就业技术指导(五):Linux运维核心管理命令详解

    一,Linux核心进程管理命令 1.1 ps:查看进程 1.1.1 命令解释 功能说明 ps命令用于列出执行ps命令的那个时刻的进程快照,就像用手机给进程照了一张照片.如果想要动态地显示进程,就需要使 ...

随机推荐

  1. Linux内核架构与底层--读书笔记

    linux中管道符"|"的作用 命令格式:命令A|命令B,即命令1的正确输出作为命令B的操作对象(下图应用别人的图片) 1. 例如: ps aux | grep "tes ...

  2. PAT1084:Broken Keyboard

    1084. Broken Keyboard (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue On a ...

  3. resteasy上传文件写法

    resteasy服务器代码 @Path(value = "file") public class UploadFileService { private final String ...

  4. 以太坊ERC20代币开发

    以太坊ERC20代币开发首先需要对以太坊,代币,ERC20,智能合约等以太坊代币开发中的基本概念有了解.根据我们的示例代码就可以发行自己的以太坊代币. 什么是ERC20 可以把ERC20简单理解成以太 ...

  5. xinetd被动服务唤醒

    rsync设置: 1.打开rsync控制开关(修改文件 /etc/default/rsync)2.sudo cp /usr/share/doc/rsync/examples/rsyncd.conf / ...

  6. MySQL索引及查询优化总结 专题

    小结:db名与应用名相同,表名:业务名_此表的作用 ,表名表示内容,不体现数量,如果表示boolean概念,表名需要使用is_业务含义来表示,但POJO中不应该出现isXXX,因为不方便序列化,中间的 ...

  7. Python分词模块推荐:jieba中文分词

    一.结巴中文分词采用的算法 基于Trie树结构实现高效的词图扫描,生成句子中汉字所有可能成词情况所构成的有向无环图(DAG)采用了动态规划查找最大概率路径, 找出基于词频的最大切分组合对于未登录词,采 ...

  8. sql复杂案例

    工作中往往会遇到非常棘手的数据查询,运营人员不知道你的数据库表是如何设计的,也不知道你的数据库记录了啥数据,他只知道自己需要看什么数据,甚至有些数据根本就不存在. 单表查询的难度: 一张数据库的表ta ...

  9. BZOJ_3365_[Usaco2004 Feb]Distance Statistics 路程统计&&POJ_1741_Tree_点分治

    BZOJ_3365_[Usaco2004 Feb]Distance Statistics 路程统计&&POJ_1741_Tree_点分治 Description     在得知了自己农 ...

  10. java的Integer与int的比较