C语言基础:timezone名字显示#include <stdio.h>#include <time.h>int main(void) { tzset(); printf("Current time zone is %s\n", tzname[0]); if (tzname[1]) ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2434浏览 1922个赞
C语言基础:文件拷贝#include <stdio.h>int main(void) { FILE *input, *output; int letter; if ((input = fopen("\\CONFIG.SYS", "r")) == NULL) printf……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2368浏览 1063个赞
C语言变成:磁盘检测代码片段#include <stdio.h>#include <dos.h>#include <malloc.h>void main(void) { struct fatinfo fat; long sector, total_sectors; void *buffer;……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3053浏览 2928个赞
C语言基础:创建文件#include <stdio.h>#include <dos.h>#include <io.h>void main(void) { int handle; if ((handle = creatnew("NEW.DAT", 0)) == -1) ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2126浏览 1969个赞
C语言基础:创建临时文件夹#include <stdio.h>#include <dos.h>#include <io.h>void main(void) { char path[64] = "C:\\TEMP\\"; int handle; if ((handle = ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1567浏览 403个赞
在N个元素中查找第K大元素,一般比较简单的方法就是先快速排序,然后直接返回array[N – K]或者利用扫描法,每一次扫描都找到当前数组中最大的元素,这个其实就是部分冒泡排序。前一种算法的时间复杂度是O(NlogN),后一种算法的时间复杂度是K*N。当然,这里我们不打算具体讨论以上两种方案,接下来看看其他方法。 &……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2221浏览 157个赞
C++获取zip文件列表 // ZipFile.h #ifndef ZIPFILE_H#define ZIPFILE_H#include <string>#include <vector>#define ZIP_O……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2617浏览 451个赞
正则表达式c语言经典实现/* * test.c * * Created on: 2012-12-4 * Author: Administrator */#include <stdio.h>int matchhere(char *,char *);int matchstar(int c,char *regexp,c……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2743浏览 1946个赞
一个简单的C语言随机数生成器int random(int start,int end){ int h; float k; h=(int)malloc(sizeof(int)); h=h%10000; k=((float)h)/10000; k=start+(end-start)*k; return k;}/** end of http……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2723浏览 690个赞
C语言设计的简单的随机数字游戏,猜数字的游戏,只能在windows下运行/********************************************************************************************| C O M M E N T……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2828浏览 1777个赞
C语言最大公约数和最小公倍数算法实现#include <iostream>#include <cstdio>#define MAX(a,b) (a > b ? a : b)template <class T>T gcd(T a, T b){ return a > b ? (b == 0 ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2488浏览 2484个赞
克努特 – 莫里斯 – 普拉特算法的C语言实现/* Copyright 2011 Shao-Chuan Wang <shaochuan.wang AT gmail.com> Permission is hereby granted, free of charge, to any person obtai……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3228浏览 2426个赞
C语言位操作代码片段/* Copyright 2011 Shao-Chuan Wang <shaochuan.wang AT gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this s……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2887浏览 1518个赞
C语言[二分图最大匹配] 匈牙利算法const int INF = 0x3f3f3f3f; const int MAXN=510;int uN,vN;//u,v数目int g[MAXN][MAXN];//构图int link[MAXN]; //link[v]=u表示右边对左边的匹配bool used[MAXN];//是否访问过bool ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2481浏览 413个赞
C++数组实现二叉树遍历来源:http://blog.csdn.net/fx397993401/article/details/6271686# includestruct node{ int l,r;};struct node tree[100];int path[100];int ans;void init(){ i……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3371浏览 1433个赞
利用UIImageView加载一序列的图像,可以实现动态图像的效果。 感谢开发者@龙龙酱丶 提供代码片段NSMutableArray * images = [NSMutableArray arrayWithCapacity:6];for (int i = 1; i <= 6; i++) { NSString * imageName =……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3281浏览 526个赞
Objective C判断设备当前的方向UIDevice *device = [UIDevice currentDevice];switch (device.orientation;) { case UIDeviceOrientationFaceUp: NSLog(@"螢幕朝上平躺"……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2864浏览 1241个赞
注意保存图片引用的images不能是autorelease的- (void) saveImagesToPhotosAlbum:(NSMutableSet *)images { if (images.count == 0) { [images release]; return; } ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2436浏览 478个赞
iOS自带的照相机功能拍照之后,可以继续保留在拍照界面- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3031浏览 1768个赞
objective C判断一个字符串 是否包含另外一个字符串+(BOOL)stringContentString:(NSString *)motherString subString:(NSString *)sonString{ if ([motherString rangeOfString:sonString].location!=NSNot……继续阅读 » 水墨上仙 5年前 (2021-03-14) 4438浏览 2514个赞
objective c 将字符转换为键盘码的代码- (int)keyCodeForCharacter: (NSString*)character { if(![character length]) return -1; char code; BOOL shift, alt; if(Ascii2Virtual( ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1656浏览 2621个赞
objective C实现iPhone图标的水晶立体效果- (void)viewDidLoad { [super viewDidLoad]; UIGraphicsBeginImageContext(icon.bounds.size); CGContextRef ctx = UIGraphicsGetCurrentContext(……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2074浏览 2952个赞
objective C实现圆角效果UIColor *color = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:0];[aImage setBackgroundColor:color]; //设置背景透明/******设置图片圆角begin*******/aImage.layer.m……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1879浏览 654个赞
题目:输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。要求不能创建任何新的结点,只调整指针的指向。   10  / /  6  14 /&……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2791浏览 2524个赞
C++多进程英文单词统计/* * * Author : shenghan , UESTC * * Time : 2012-11-02 * * Function : A word frequency statistics tool, usage wordscan scan_dir results * */#in……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1843浏览 1968个赞
slice 指向数组的值,并且同时包含了长度信息。[]T 是一个元素类型为 T 的 slice。package mainimport "fmt"func main() { p := []int{2, 3, 5, 7, 11, 13} fmt.Println("p ==", p) for i := 0; ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3488浏览 752个赞
map 映射键到值。map 在使用之前必须用 make 来创建(不是 new);一个值为 nil 的 map 是空的,并且不能赋值。package mainimport "fmt"type Vertex struct { Lat, Long float64}var m map[string]Vertexfunc main……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3480浏览 596个赞
表达式 new(T) 分配了一个零初始化的 T 值,并返回指向它的指针。var t *T = new(T)或t := new(T)package mainimport "fmt"type Vertex struct { X, Y int}func main() { v := new(Vertex) fmt.Printl……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1598浏览 2221个赞
结构体文法表示通过结构体字段的值作为列表来新分配一个结构体。使用 Name: 语法可以仅列出部分字段。(字段名的顺序无关。)特殊的前缀 & 构造了指向结构体文法的指针。package mainimport "fmt"type Vertex struct { X, Y int}var ( p = Vertex{1……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1672浏览 2745个赞
Go 有指针,但是没有指针运算。结构体字段可以通过结构体指针来访问。通过指针间接的访问是透明的。package mainimport "fmt"type Vertex struct { X int Y int}func main() { p := Vertex{1, 2} q := &p q.X = 1e9……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1828浏览 2093个赞
一个结构体(struct)就是一个字段的集合。(而 type 定义跟其字面意思相符。)package mainimport "fmt"type Vertex struct { X int Y int}func main() { fmt.Println(Vertex{1, 2})} ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2387浏览 2679个赞
if 语句看起来跟 C 或者 Java 中的一样,除了没有了 ( ) 之外(甚至强制不能使用它们),而 { } 是必须的。package mainimport ( "fmt" "math")func sqrt(x float64) string { if x < 0 { return sqr……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2001浏览 435个赞
常量的定义与变量类似,只不过使用 const 关键字。常量可以是字符、字符串、布尔或数字类型的值。package mainimport "fmt"const Pi = 3.14func main() { const World = "世界" fmt.Println("Hello", ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2932浏览 1593个赞
Go 只有一种循环结构,for 循环。所以for循环在golang里显得格外重要,基本的 for 循环看起来跟 C 或者 Java 中做的一样,除了没有了 ( ) 之外(甚至强制不能使用它们),而 { } 是必须的。package mainimport "fmt"func main() { sum := 0 for i :=……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1897浏览 1083个赞
var 语句定义了一个变量的列表;跟函数的参数列表一样,类型在后面。package mainimport "fmt"var x, y, z intvar c, python, java boolfunc main() { fmt.Println(x, y, z, c, python, java)}变量定义可以包含初始……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2042浏览 844个赞
函数可以返回任意数量的返回值。这个函数返回了两个字符串。package mainimport "fmt"func swap(x, y string) (string, string) { return y, x}func main() { a, b := swap("hello", "wor……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2063浏览 1936个赞
函数可以没有参数或接受多个参数。在这个例子中,add 接受两个 int 类型的参数。注意类型在变量名之后。package mainimport "fmt"func add(x int, y int) int { return x + y}func main() { fmt.Println(add(42, 13))}……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1710浏览 2029个赞
每个 Go 程序都是由包组成的。程序运行的入口是包 main。这个程序使用并导入了包 “fmt” 和 “math”。按照惯例,包名与导入路径的最后一个目录一致。package mainimport ( "fmt" "math")func main() {……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3211浏览 179个赞
go语言版的ip2long 函数,该函数不会对 IP 的合法性进行校验// 注意: 该函数不会对 IP 的合法性进行校验func Ip2Long(ip string) (ips string) { var ip_pieces = strings.Split(ip, ".") ip_1, _ := strconv.Pars……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2102浏览 522个赞
go语言base64使用代码 golang base64 的一个小例子package main import ( "fmt" "encoding/base64")……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1496浏览 1453个赞
go语言 strconv.ParseInt 的例子 golang strconv.ParseInt 是将字符串转换为数字的函数,功能灰常之强大,看的我口水直流.func ParseInt(s string,……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2956浏览 804个赞
golang strconv atoi itoa 在做任何项目的时候都要用到字符串和数字,相互转换是最近基本的操作,哈哈 这里就介绍golang怎么做这些事情 参考代码如下:package main import ( "strconv")……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3491浏览 444个赞
go语言按显示长度截取字符串 根据显示长度截取字符串,之前php用的utf8编码,10个英文和10个汉字的显示长度差距太大,按字节截取的话又会出错出现截取半个汉字的情况,所以写了这两个函数.这两天在折腾golang,所以就用golang重写了着连个函数.代码如下:package ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2044浏览 1250个赞
golang的template包很好用,做一些复杂的文本格式生成太有帮助了,生成网页也是很不错的,使用起来非常方便package main import ( "fmt" "os" "text/template") type Latlng struct ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2466浏览 1762个赞
超简易Go语言实现的留言板代码package main import ( // "fmt" "io" "log" "net/http" "text/template" "time&quo……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2049浏览 318个赞