编程语言

Java多线程实践

赵裕(vimerzhao)
1.实现Runnable接口 1 import java.util.Random; 2 3 4 public class PrintTask implements Runnable{ 5 private final int sleepTime; 6 private final String taskName; 7 private final static Random generator = new Random(); 8 9 10 public PrintTask(String name) { 11 taskName = name; 12 sleepTime = generator.nextInt(5000); 13 } 14 15 @Override 16 public void run() { 17 try { 18 System.out.printf("%s going to Sleep for %d milliseconds.\n", 19 taskName, sleepTime); 20 Thread.sleep(sleepTime); 21 } catch (InterruptedException e) { 22 System.out.printf("%s %s\n", taskName, "terminated prematurely" + 23 "

C语言实现penna模型

赵裕(vimerzhao)
一年前写的代码,偶然翻出来。发现自己当时水平还不赖吗。 1 # include <stdio.h> 2 # include <stdlib.h> 3 # include <time.h> 4 # include <stdbool.h> 5 # include <windows.h> 6 7 # define N0 1000 //初始时刻种群数量为1000 8 # define Nmax 100000 //种群最大数量为100000 9 # define R 6 //最低繁殖年

C语言用面向对象的思想写贪吃蛇

赵裕(vimerzhao)
大概一年前这时候,接触C语言一个月,那时候知之甚少,对面向对象只觉”可远观而不可亵玩“,而且会看到很多言论说C语言就是面向过程的语言,C++就是面向对象的语言。不过,不记得什么时候在网上看到过一篇博文

深入学习 memset 函数

赵裕(vimerzhao)
最近,和同学讨论了一下memset函数,趁着周五空闲做一总结。 memset函数最常用的功能就是初始化数组了(主要是置零),如 #include <iostream> #include <cstring> using namespace std; int main(int argc, char const *argv[]) { int A[10]; memset(A, 0, sizeof(A)); cout << A[0] << '\t' << A[1] << endl; return 0; } 输出 0 0 但是,

C语言实现贪吃蛇源码

赵裕(vimerzhao)
先放效果 源代码 //2016-2-12 //zhaoyu //Gmail:zhaoyu1995.com@gmail.com //Language: C //Platform:Code::Blocks #include <stdio.h> #include <windows.h> #include <stdlib.h> #include <time.h> typedef struct snake { int x; int y; struct snake *next; }Snake; int X, Y; enum STATUS{Up = 1, Down, Left, Right}; Snake *pHead, *pBody;//the head of the snake enum STATUS Direction; int score=0, scorePerFood=10; int gameStatus = 0; int timeInterval = 200; void gameEnd(void); void setPosition(int x, int y) { COORD pos; HANDLE hOutput; pos.X = x; pos.Y = y; hOutput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOutput, pos); } void hideCursor() { CONSOLE_CURSOR_INFO cursor_info = { 1, 0 }; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);