n********y 发帖数: 48 | 1 程序的基本结构如下所示,
class priceserv{
public:
priceserv(){
}
virtual ~priceserv(){
}
int run()
{
// connect to the price server
// waiting for the price events, and call the corresponding
callback function.
}
//callback function
bool on_quote(char *data)
{
//printf data
}
bool on_trade(char *data)
{
//printf data
}
bool on_depth(c... 阅读全帖 |
|
m********r 发帖数: 334 | 2 1)
#pragma pack(1)
typedef struct
{
unsigned int a:22;
unsigned int b:10;
unsigned int c:20;
unsigned char d:6;
unsigned char e:6;
unsigned int f:10;
unsigned char g:3;
unsigned char h:3;
} S1 ;
#pragma pack()
2)
typedef struct
{
unsigned int a:22;
unsigned int b:10;
unsigned int c:20;
unsigned char d:6;
unsigned char e:6;
unsigned int f:10;
unsigned char g:3;
unsigned char h:3;
} __attribute__ ((packed)) S2 ;
为什么sizeof(S1)=1... 阅读全帖 |
|
d****n 发帖数: 1637 | 3 献丑了,have fun!
#include
#include
#include
#include
#define IS_WHITE_SPACE(c ) ( isblank((c)))
char * replace_white_space( const char *source, size_t source_len){
size_t used=0, inc=0, allocated=source_len+1;
char *ret= (char *)malloc(sizeof(char)*allocated );
const char *s=source;
while(*s++){
(IS_WHITE_SPACE (*(s-1)))? (inc=3):(inc=1);
if ((used+=inc)>=allocated)
ret=(char *)realloc(ret, sizeof(char)*(alloc... 阅读全帖 |
|
h********o 发帖数: 103 | 4 CHAR变量 is your original variable.
SCAN(string,1,delimiter) is the Nth sub-string delimited by delimiter.
SCAN("01\21\2001",1,"") = 01
SCAN("01\21\2001",2,"") = 21
SCAN("01\21\2001",2,"") = 2001
The full code look like this
================================
DATA OLD;
INPUT CHAR : $10.;
CARDS;
3\3\1996
10\4\2006
10\20\2006
4\15\1997
13\15\1996
11789
;
DATA GOOD BAD(DROP = DATE);
SET OLD;
IF INDEX(CHAR,"") THEN DO;
MONTH = INPUT(SCAN(CHAR, 1, ""),$2.);
DAY = INPUT(SCAN(... 阅读全帖 |
|
r****o 发帖数: 1950 | 5 刚才试了一下,两个const按存在不存在取4种组合,函数都能正确工作,除了一些
warning以外。
const char *function1(void)
{
const char *s = "12345";
return s;
}
const char *function2(void)
{
char *s = "12345";
return s;
}
char *function1(void)
{
const char *s = "12345";
return s;
}
char *function1(void)
{
char *s = "12345";
return s;
}
是不是这4个函数等价? |
|
d**f 发帖数: 264 | 6 void swap( char* cA, char* cB)
{
char ct = *cA;
*cA = *cB;
*cB = ct;
}
int main(int argc, char* argv[])
{
char *a = "a";
char *b = "b";
swap(a, b);
}
貌似问题出在 *cA = *cB;?
如果是char a = 'a'; char b = 'b'; swap(&a,&b);不会有segment fault. |
|
l********y 发帖数: 1327 | 7 每次执行到*c1 = *c2的时候就出错,如果仅仅是swap两个char没问题,但是用C的char
数组时就不行,这里也没有牵涉到'\0'啊,不明白?
char * c = "abcde";
char * c1 = &c[0];
char * c2 = &c[4];
swap(c1,c2);
void swap(char * c1, char * c2){
char temp = *c1;
*c1 = *c2;
*c2 = temp;
} |
|
s*****y 发帖数: 897 | 8 Sounds good. I write the code according to your idea. But still need to defi
ne a 256 byte array to hash the reference string and count the times they ap
pear.
Any better way I could ger rid of the 256 byte array?
#define SWAP(A,B) { \
char tmp; \
tmp = A; \
A = B; \
B = tmp; }
char input[] = "ABBFKCEDGAB";
char pattern[] = "BAC";
void SortString(char input[], char pattern[])
{
char hash[256] = {0};
int i,j;
int count;
i = 0;
while... 阅读全帖 |
|
g**********y 发帖数: 14569 | 9 我写的慢程序:用HashMap实现的Trie. 换成char[], 对于N=7, 速度快一些,但是对N<
7, 速度更慢。可能因为解跟Hash key的位置有关。
public class WordRectangle {
private final static String DIR = "src/test/resources";
private Trie m_trie;
private String[] m_words;
public static void main(String[] args) {
WordRectangle w = new WordRectangle();
long t0 = System.currentTimeMillis();
w.find(6);
long t1 = System.currentTimeMillis();
System.out.println("Time = " + (t... 阅读全帖 |
|
p****e 发帖数: 37 | 10 贴个楼主事后写的:
bool _re_match(const char *str, const char *pattern, char prev_char) {
// 如果str匹配完,检查pattern是否匹配完,或者还剩一个"*"
if (*str == NULL)
return (*pattern == NULL || (*pattern == '*' && *(pattern+1) == NULL
)) ? true : false;
if (*pattern != '*')
{
// 如果当前pattern char不是'*', 试图匹配当前的str char, 然后
继续。
if (*pattern == '.' || *pattern == *str)
{
if (_re_match(str+1, pattern+1, *pattern))
return true;
... 阅读全帖 |
|
p****e 发帖数: 37 | 11 贴个楼主事后写的:
bool _re_match(const char *str, const char *pattern, char prev_char) {
// 如果str匹配完,检查pattern是否匹配完,或者还剩一个"*"
if (*str == NULL)
return (*pattern == NULL || (*pattern == '*' && *(pattern+1) == NULL
)) ? true : false;
if (*pattern != '*')
{
// 如果当前pattern char不是'*', 试图匹配当前的str char, 然后
继续。
if (*pattern == '.' || *pattern == *str)
{
if (_re_match(str+1, pattern+1, *pattern))
return true;
... 阅读全帖 |
|
S**I 发帖数: 15689 | 12 ☆─────────────────────────────────────☆
honeydream (pretty) 于 (Fri May 6 00:30:21 2011, 美东) 提到:
下面这个程序为啥会segmentation fault呢?
int main(void)
{
char *p1, *p2;
*p1 = 'a';
*p2 = 'b';
printf("%c %c\n", *p1, *p2);
return 0;
}
如果我不用指针,把p1,p2的星号都去掉,就可以输出正确结果。
☆─────────────────────────────────────☆
chenpp (chenpp) 于 (Fri May 6 00:31:43 2011, 美东) 提到:
p1和p2浮空,指向未定义的地址空间。
对未定义的地址空间进行读写操作会导致未定义的行为,包括段错。
☆─────────────────────────────────────☆
mercuriusl (Mercurius) 于 (Fri May 6 ... 阅读全帖 |
|
c*****n 发帖数: 96 | 13 char* readLine(){
static char[BUFSIZE] buf;
static char* ptr = buf;
static int bufSize = 0;
int outputSize = 0;
char *output = NULL;
while (1){
int pos = getNewLinePos(ptr, bufSize);
if (pos > 0){
// found new line char in the buffer
output = realloc(output, outputSize+pos+1); // one extra char for '
\0'
// TODO: check realloc return value
memcpy (output + outputSize, ptr, pos);
output[outputSize + pos] = '\0';
... 阅读全帖 |
|
h*****g 发帖数: 312 | 14 多谢你的解答 觉得 //1 处的outputSize 应该时刻更新吧?
char* readLine(){
static char[BUFSIZE] buf;
static char* ptr = buf;
static int bufSize = 0;
int outputSize = 0;
char *output = NULL;
while (1){
int pos = getNewLinePos(ptr, bufSize);
if (pos > 0){
// found new line char in the buffer
output = realloc(output, outputSize+pos+1); // one extra char for '
\0'
// TODO: check realloc return value
memcpy (output + outputSize, ptr, pos);
outpu... 阅读全帖 |
|
w****x 发帖数: 2483 | 15 /*
scramble string,judge if one string can be scrambled to another one
tiger
/ \
ti ger
/ \ / \
t i g er
/ \
e r
rotation is allowded
itreg
/ \
it reg
/ \ / \
t i g re
/ \
e r
then tiger can be changed to itreg
*/
bool _inner_can_scramble(const char* szStr1, const char* szStr2, int n);
bool CanScramble(const char* szStr1, const char* szStr2)
{
assert(szStr1 && szStr2);
int nLen1 = strlen(szStr1);
int nLen2 = strlen(szStr2);
if (nLen1 !... 阅读全帖 |
|
w****x 发帖数: 2483 | 16 贴一个递归和DP的:
/*
scramble string,judge if one string can be scrambled to another one
tiger
/ \
ti ger
/ \ / \
t i g er
/ \
e r
rotation is allowded
itreg
/ \
it reg
/ \ / \
t i g re
/ \
e r
then tiger can be changed to itreg
*/
bool _inner_can_scramble(const char* szStr1, const char* szStr2, int n);
bool CanScramble(const char* szStr1, const char* szStr2)
{
assert(szStr1 && szStr2);
int nLen1 = strlen(szStr1);
int nLen2 = strlen(szStr2);
... 阅读全帖 |
|
w****x 发帖数: 2483 | 17 /*
scramble string,judge if one string can be scrambled to another one
tiger
/ \
ti ger
/ \ / \
t i g er
/ \
e r
rotation is allowded
itreg
/ \
it reg
/ \ / \
t i g re
/ \
e r
then tiger can be changed to itreg
*/
bool _inner_can_scramble(const char* szStr1, const char* szStr2, int n);
bool CanScramble(const char* szStr1, const char* szStr2)
{
assert(szStr1 && szStr2);
int nLen1 = strlen(szStr1);
int nLen2 = strlen(szStr2);
if (nLen1 !... 阅读全帖 |
|
w****x 发帖数: 2483 | 18 struct NODE
{
string str;
NODE* pLft;
NODE* pRgt;
NODE(const char* szStr = "") : str(szStr), pLft(NULL), pRgt(NULL) {}
};
void serialize(NODE* pNode, char*& p)
{
if (p == NULL) return;
if (pNode == NULL)
{
*((int*)p) = 0;
p += sizeof(int);
return;
}
int nLen = pNode->str.length();
*((int*)p) = 1;
p += sizeof(int);
strcpy(p, pNode->str.c_str());
p += nLen+1;
serialize(pNode->pLft, p);
serialize(pNode->pRgt... 阅读全帖 |
|
h******2 发帖数: 13 | 19 有哪位大神能详细讲一下 二面中的两道题吗?
对于第二道题, 我能想到的是:
可以用一个map > m_Indexes;
对于每个char,value中记录了index列表。 然后对于T中的每个char,先找第一个char
的leftest位置(smallest index), then find the second char, and it’s index
must be greater than the first’s char ‘s smallest index(that’s upper_
bound), and we do it iteratively until we all found it or not.
第一道 cactus的不太清楚怎么做啊?
二面
1. given a cactus graph, determine the number of different spanning trees of
this graph.
2. Given a very large string T, |T| = 10 000 000 cha... 阅读全帖 |
|
c*****a 发帖数: 808 | 20 char[256] set + 2个指针
检查isAnagram用constant time 256,就是O(1)
总共就是O(n) time, O(1) space, 256space是constant...
public boolean isAnagram(char[]s1,char[]s2){
int i=0;
for(char c:s1)
if(c!=s2[i++]) return false;
return true;
}
public boolean checkAna(String s1,String s2){
if(s1==null || s2==null)return false;
if(s2.length()==0) return true;
if(s1.length()
char[] set1 = new char[256];
char[] set2 = new char[256];
for(int i=0;i阅读全帖 |
|
n*****g 发帖数: 16 | 21 My version for C#.
static bool IsValidExpression(string expression)
{
Stack stackOperator = new Stack();
Stack stackOperand = new Stack();
int length = expression.Length;
int i;
char opr;
for (i = 0; i < length; ++i)
{
if (expression[i] == '(' || expression[i] == '+' ||
expression[i] == '-' || expression[i] == '*' || expression[i] == '/')
{
... 阅读全帖 |
|
n*****g 发帖数: 16 | 22 My version for C#.
static bool IsValidExpression(string expression)
{
Stack stackOperator = new Stack();
Stack stackOperand = new Stack();
int length = expression.Length;
int i;
char opr;
for (i = 0; i < length; ++i)
{
if (expression[i] == '(' || expression[i] == '+' ||
expression[i] == '-' || expression[i] == '*' || expression[i] == '/')
{
... 阅读全帖 |
|
x*********w 发帖数: 533 | 23 以前有写过这题,不知道对不对
========================================================
/*
有个封装好的函数int block_reader(char *buf),内部有个静态文件指针,
只能向文件末尾移动,不能rewind,每次只能读取K的block到buf里,返回读取
的字节数(除非到文件尾,否则总是K)要求实现int anysize_reader(char *buf, int
size)从文件的
当前位置读取任意大小的数据存入buf,并返回实际读到的数据字节数,白板写code
*/
const int k = 1024;
char buffer[k];
int nSize = 0;
int block_reader(char *buf);
void moveToBuf(char*& pWriter, int n)
{
if (n <= 0 || pWriter == NULL || nSize < n)
return;
memcpy(pWriter, buffer, n);
... 阅读全帖 |
|
a********n 发帖数: 1287 | 24 用suffix array
char* LongestCommonSubStr( char* a, char* b )
{
if( !a || !b )
{
return NULL;
}
int sizea = strlen( a );
int sizeb = strlen( b );
char** suffix = new char*[sizea + sizeb];
int suffixIdx = 0;
for( int i = 0; i < sizea; i++ )
{
suffix[suffixIdx++] = a + i;
}
for( int i = 0; i < sizeb; i++ )
{
suffix[suffixIdx++] = b + i;
}
std::sort( suffix, suffix + sizea + sizeb, Comp() );
int maxLen = 0;
char* ... 阅读全帖 |
|
b******7 发帖数: 92 | 25 分两步:先压缩连续出现次数大于1的字符,再压缩连续出现次数为1的字符
int print_number(int num, char * buf)
{
assert(num >0);
char * p = buf;
while(num > 0)
{
*p++ = num%10 + '0';
num /= 10;
}
//[buf,p) reverse
int len = p - buf;
for(p--;buf < p; buf++,p--)
{
char tmp = *buf;
*buf = *p;
*p = tmp;
}
return len;
}
void compress(char * src)
{
if(src == NULL || *src == '\0') return;
char * p0 = src;
int singlenum = 0;
char * start = src;
... 阅读全帖 |
|
r*c 发帖数: 167 | 26 RK肯定好写些,尽管它比KMP要慢不少。
前些天看到一个帖子,把RK的实现搞得特麻烦。下面贴个改进的,其中hash function
可替换,只要把各个char的信息都用到就好了。
class RobinKarpSolution
{
public:
char *strStr(char *haystack, char *needle) {
int nHSLen = strlen(haystack), nNDLen = strlen(needle);
if(nNDLen > nHSLen) return NULL;
int h_hash, n_hash = hashAString(needle, nNDLen, 0);
for(int i = 0; i <= nHSLen-nNDLen; ++i){
h_hash = hashAString(haystack, nNDLen, i);
if(n_hash == h_hash) {
if(!C... 阅读全帖 |
|
f**********t 发帖数: 1001 | 27 class Component {
public:
virtual char next() = 0;
virtual bool hasNext() = 0;
virtual void traverse() = 0;
};
class Leaf : public Component {
char val;
bool _hasNext;
public:
Leaf(char v) : val(v), _hasNext(true) { }
char next() {
_hasNext = false;
return val;
}
bool hasNext() {
return _hasNext;
}
void traverse() {
cout << val << ' ';
}
};
class Composite : public Component {
vector children;
size_t _idx = 0;
void goNext() {
while (_... 阅读全帖 |
|
m*****l 发帖数: 95 | 28 随便给个思路。
public static Set generateStrings(String input) {
Set stringSet = new HashSet();
if(input != null) {
List questionMarks = new ArrayList();
char[] chars = input.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '?') {
questionMarks.add(i);
} else if (chars[i] != '0' && chars[i] != '1') {
throw new Illega... 阅读全帖 |
|
t*******e 发帖数: 274 | 29 电面那题,网上看到一种解法,这是正解么?
我有点不明白的是假如只有200bytes, 通过read4096之后是不是应该返回200(<4096)
作为结果?
public class read_4096_bytes {
public int read4096(char[] buf) {
return 4096;
}
public int read(int n, char[] buf) {
int totalRead = 0;
for (int i = 0; i < n / 4096; ++i) {
char[] tbuf = new char[4096];
int tRead = read4096(tbuf);
totalRead += copyTo(buf, totalRead, tbuf, tRead);
if (tRead < 4096) {
return totalRead;
... 阅读全帖 |
|
y*****e 发帖数: 712 | 30 题意我有点迷糊,不明白为啥public int read(char[] buf, int n)给出说buf是
destination buffer,
但看了答案之后半懂不懂的写了一个c++的,通过了,是这样的
int read(char *buf, int n) {
bool eof=false;
int readBytes=0;
while(!eof && readBytes<=n)
{
int sz=read4(buf);
if(sz<4) eof=true;
int bytes = min(n - readBytes, sz);
readBytes+=bytes;
buf+=bytes;
}
return readBytes;
}
大概的思路就是每次用read4从buf里读,然后指针往后挪,一直挪到eof或者n reached
,这里的buf应该和... 阅读全帖 |
|
C****p 发帖数: 6 | 31 我的java代码,暴力两层dfs,672ms竟然过了。。。
第一层遍历所有数字组合,第二层遍历所有运算符组合,calculate的时候用了deque来
处理乘法优先的情况
不得不说这题有点变态,好像是G家的面试题?
public class Solution {
public List addOperators(String num, int target) {
List ans = new ArrayList();
if (num == null || num.length() == 0) {
return ans;
}
char[] digits = num.toCharArray();
List numbers = new ArrayList();
dfs(ans, target, numbers, digits, 0);
return ans;
}
... 阅读全帖 |
|
c*****m 发帖数: 271 | 32 感觉蛮难的。1.2 是加强版的Regular Expression Matching么;3我之前也做过,不
过现在看到也没想起来;2我觉得可以用Trie啊,写了个如下,请拍
class Solution():
def matchString(self, pattern_list, search_list):
#build trie based on pattern_list
trie = {}
for one_str in pattern_list:
#add each string into the trie
node = trie
for char in one_str:
if char not in node:
node[char] = {}
node = node[char]
#suppose strings do not h... 阅读全帖 |
|
s******g 发帖数: 755 | 33 【 以下文字转载自 Apple 讨论区 】
发信人: faucetQ (fq), 信区: Apple
标 题: [Mac Dev]整了个ObjectiveC的笔记,看看气氛对得上不
发信站: BBS 未名空间站 (Mon Feb 2 21:38:18 2009), 转信
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk... 阅读全帖 |
|
f*****Q 发帖数: 1912 | 34 整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk的语法基本是相同的。
当有两个或者两个以上的参数时,通常试用以的语法
[ obj method:parameter1 WithSecondParameter:parameter2];
定义一个类的代码放在一个.h文件中,下面是一个例子。
//macdevexample1.h
... 阅读全帖 |
|
c*****i 发帖数: 25 | 35 我知道这些问题显得都很笨。请表拍我。谢谢您的指教。
比如说下面这段code
struct a {
char *b;
int c;
};
int n, m, i;
struct a *pa = (struct a*)malloc(n, sizeof(struct a));
for(i = 0; i < n; i++) {
pa[i].b = (char*)malloc(m, sizeof(char));
}
//需要把每一个pa[i].b都free吗?
for(i = 0; i < n; i++) {
free(pa[i].b);
}
//还是只有这句就够了?
free(pa);
还有一段code: :)
char **s;
int n, m, i;
s = (char**)malloc(n, sizeof(char*));
for(i = 0; i < n; i++) {
s[i] = (char*)malloc(m, sizeof(char));
}
// 需要把每一个s[i]都free吗?
for(i = 0; i < n; i++) {
fre |
|
g*********s 发帖数: 1782 | 36 the following two str_cmp have the diff on the major loop. which one is
better?
the 1st seems better in the look. but it does have the side effect that
p and q are possibly pointing to unknown memory location.
so i prefer the 2nd. anyone agree?
int str_cmp(const char* str1, const char* str2) {
if ( str1 == str2 ) {
return 0;
}
if ( str1 == NULL || str2 == NULL ) {
return (str1 == NULL ? -1 : 1);
}
const char* p = str1;
const char* q = str2;
int res (0)... 阅读全帖 |
|
p*********t 发帖数: 2690 | 37 2网友的意见不同,哪个是对的?
newpolice -- function char *m() {} is valid
Xentar -- it's undefined.
char *m()
{
char str[50];
strcpy(str,"how are you");
return str;
}
int main()
{
char s[50];
strcpy(s,m());
printf("%s",s);
//cin.get();
return 0;
}
为什么结果可以正确输出呢?我知道return by pointer可以make copy,可是return之
后storage不是free了吗?
另外,为什么下面这个就只能由一部分正确输出?
char *m()
{
char str[20];
strcpy(str,"how are you");
return str;
}
int main()
{
printf("%s",m());
//cin.get();
return 0;
}
然后上面char str[20];改成比如cha... 阅读全帖 |
|
p*****e 发帖数: 53 | 38 实在看不出哪里不对,只能来这里求助高手帮忙看看了
非常感谢!!!
1.
int IsSecretPassword(char *ptrstring)
{
char temp[1024];
if(ptrstring)
{
strcpy(temp, ptrstring);
for (int i =0; i
{
temp[i] = toupper(temp[i]);
}
if (strcmp(temp, "TEST")==0)
return 1;
else
return 0;
}
return 0;
}
2.
int* MakeArray(int nsize)
{
int *ptr = 0;
if(nsize <=0)
return NULL;
ptr = (int*)malloc(sizeof(int... 阅读全帖 |
|
x******a 发帖数: 6336 | 39 装了一个quantlib在mac os x上,然后运行那个example,结果得到下面一堆。请教应
该link或者编译?
谢谢!
instruction在这里:
http://quantlib.org/install/macosx.shtml
run example
g++ -I/opt/local/include/ -I/opt/local/include/boost BermudanSwaption.cpp
-o bermudanswaption -L/opt/local/lib/ -lQuantLib
以后的error:
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
"vtable for boost::unit_test::unit_test_log_t", referenced from:
boost::unit_test::unit_test_log_t::unit_test_log_t()in ccL... 阅读全帖 |
|
k*******3 发帖数: 1909 | 40 下面这个程序来自Data structures and algorithms in C++ by Adam Drozdek
第四章的迷宫(maze)程序。
我的疑问是最后几行main函数里面的Maze().exitMaze();怎么解释,我想不通语法是怎
么样的。
Maze()是调用哪个函数呢?如果是Maze class的Maze() constructor,难道不用先定义
一个Maze 对象吗?
谢谢。
#include
#include
#include
using namespace std;
template
class Stack : public stack {
public:
T pop() {
T tmp = top();
stack::pop();
return tmp;
}
};
class Cell {
public:
Cell(int i = 0, int j = 0) {
x = i; y... 阅读全帖 |
|
m*********a 发帖数: 3299 | 41 const char i='x';
const char *cp=&i;
char *p;
p=const_cast(cp);
std::cout<<&i<<" "<
address
*p='y';
std::cout<<*p<
std::cout<<*cp<
std::cout<
同样的
char i='x';
const char *cp=&i;
char *p;
p=const_cast(cp);
std::cout<<&i<<" "<阅读全帖 |
|
x******a 发帖数: 6336 | 42 按照quantlib.org上在mac上安装以后,测试一个命令行:
g++ -I/opt/local/include/ -I/opt/local/include/boost BermudanSwaption.cpp \
-o bermudanswaption -L/opt/local/lib/ -lQuantLib
得到i686-apple-darwin10-g++-4.2.1: BermudanSwaption.cpp: No such file or
directory。
然后到/opt/local/include/boost目录下,再次运行上面的命令行,显示下面的内容
g++ -I /opt/local/include/ -I /opt/local/include/boost BermudanSwaption.cpp
-o bermudanoption -
L/opt/local/lib/ -lQuantLib1.0.1
ld: library not found for -lQuantLib1.0.1
collect2: ld returned 1 exit statu... 阅读全帖 |
|
y*********e 发帖数: 518 | 43 视 string 为 bag of chars。把 s1 和 s2 分别转换成 bag of chars,然后找 s1 里
面最小的 substring,使得前者 bag 包含后者。O(n + m),这里 n 和 m 分别是
s1 和 s2 的长度。
要注意一个 corner case:s1 不包含 s2 所有的 char。比如,s1 = "abc", s2 = "d"
/* C# code
*
* returns null if not found
* assumes ASCII
*/
public string FindSmallestSubStringContains(string s1, string s2) {
if (s2.Length == 0) return String.Empty;
if (s1.Length == 0) return null; // not found
char[] bag1 = new char[128];
char[] bag2 = new char[128];
forea |
|
c***2 发帖数: 838 | 44 /*
sizeOfArray: how many lines
sizeOfRecord: size of each line
*/
unsigned char **get(int sizeOfArray, int sizeOfRecord)
{
unsigned char **p;
int i;
p=(char**)malloc(sizeof(char*)*sizeOfArray);
for(i=0;i
p[i]=(char*)malloc((sizeOfRecord+1)*sizeof(char));
}
return p;
}
void release(unsigned char **ptr, int sizeOfArray)
{
int i;
for(i=0;i
free(ptr[i]);
}
free(ptr);
} |
|
c***2 发帖数: 838 | 45 Ok. I play it further to get a utility program.
==================================================
/* telwords.c
Given a telephone number (or any number),
print all possible words based on
digits-letters mapping from telephone key pads.
*/
#include
#include
#include
static char *digitsmaps[]={
"0",
"1",
"ABC",
"DEF",
"GHI",
"JKL",
"MNO",
"PQRS",
"TUV",
"WXYZ",
"#",
NULL
};
void doPrintTelephoneWo... 阅读全帖 |
|
f****g 发帖数: 313 | 46 The following is my code :S
#include
#include
#include
#define MAXLEN 5
char* countCharInStr(const char* s,
unsigned int len)
{
char *pFast, *pSlow;
unsigned char num[MAXLEN] = {0};
unsigned int count = 0;
unsigned int resC = 0;
if( 0 == len || NULL == s)
{
return NULL;
}
char *res = (char*)malloc(sizeof(char)*len);
if( NULL == res)
{
return NULL;
}
pSlow = s;
pFa... 阅读全帖 |
|
r******r 发帖数: 700 | 47 Complexity 是多少? 别运行,试试看。
public static void mysteriousAlgorithm(String st, String chars) {
if (chars.length() == 1)
System.out.println(st + "" + chars);
else
for (int i = 0; i < chars.length(); i++) {
String newString = chars.substring(0, i) + chars.
substring(i + 1);
mysteriousAlgorithm(st + chars.charAt(i), newString);
}
} |
|
c***2 发帖数: 838 | 48 agree.
1) in place
char *reverse(char *str)
2) into another buf version 1
char *reverse(const char *src, char *dst)
3) into another buf version 2
char *reverse(const char *src) |
|
g**u 发帖数: 583 | 49 马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array with repeated elements
for given element, find out its range.
e.g. A A B B B B B C C D D E F ... 阅读全帖 |
|
S**I 发帖数: 15689 | 50 ☆─────────────────────────────────────☆
libei (Bei) 于 (Wed Jan 11 15:43:39 2012, 美东) 提到:
面试官是Google+组的,
一上来她说看到我简历上的一篇测试自动化的文章,读了一遍,感觉"very
informative",让后让我介绍一下相关经验。让我小高兴了一下。
第一题是coding,做的还算顺利,后来她评价说所有的cases都覆盖到了。可能算是过
关吧。
第二题我想复杂了,然后在她提示下才解决。自我感觉很不好。其实sort一下就差不多
了,不过我往复杂的树结构想去了。虽然树结构确实能解决这个问题,不过当时我解释
得很不清楚。反正很不爽。
最后瞎聊时间,她说我提到的测试自动化实践和Google内部的基本完全一样blahblah。
。。,不过我觉得这点也算不上加分吧,是个人进google一段时间后都能学会。就怕她
觉得我想问题太复杂,直接negative。
大家有啥建议想法??
☆─────────────────────────────────────☆
peking2 (myfac... 阅读全帖 |
|