The C Programming Language 经典代码 any(s1,s2)
/*
* Exercise 2-5 Page 48
*
* Write the function any(s1,s2), which returns the first location
* in the string s1 where any character from the string s2 occurs,
* or -1 if s1 contains no characters from s2. (The standard library
* function strpbrk does the same job but returns a pointer to the
* location.)
*
*/
Here's a much better solution, by Partha Seetala. This solution has a worst-
case time complexity of only O(n + m) which is considerably better.
相关文档:
C版本:
vim stash.h
#ifndef STASH_H
#define STASH_H
typedef struct STASHTag {
int size; /* Size of each space */
int quantity; /* Number of storage spaces */
int next; /* Next empty space */
/* Dynamically allocated array of bytes: */
unsigned char* ......
/***
*strtok.c - tokenize a string with given delimiters
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* defines strtok() - breaks string into series of token
* via repeated calls.
*
************************************************************** ......
比如 输入1.9会显示1.899999 类似的问题
由于C语言中对于浮点小数的表达方式的局限导致的。C语言中10进制小数是直接用2进制小数来表示的。由于某些10进制小数根本无法用2进制小数来精确表达,譬如0.1,导致计算机不得不用近似的相差很小的2进制小数来表示这些10进制小数。
既然是近似,就一 ......
< type="text/javascript">
原文请见这里
。
GNU
C的一大特色(却不被初学者所知)就是__attribute__机制。__attribute__可以设置函数属性(Function
Attribute)、变量属性(Variable Attribute)和类型属性(Type Attribute)。
__attribute__书写特征是:__attribute__前后都有两个下划 ......
单例模式:对应一个类只能生成一个对象。
#include <stdio.h>
class A
{
private:
int id;
A() {}//把构造函数放在private:下目的是在类外不能在栈上直接分配空间定义对象。
public:
static A *pt;
static A *instance()
  ......