W*****x 发帖数: 684 | 1 $ cd geoip-api-c-master
$ libtoolize
$ aclocal
$ autoconf
$ automake --add-missing
$./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
... 阅读全帖 |
|
k****e 发帖数: 126 | 2 If a[][] is declared as static storage duration then it will certainly go to
.data segment. If not, the compiler will probably use immediate value
instead.
If you compare the following, (gcc version 4.5.3 -O0)
(1) array a[] has "auto" storage duration.
#include
#include
int foo()
{
int a[] = {3, 4, 5};
return a[2];
}
int main(void)
{
int temp;
temp = foo();
printf("%d", temp);
return 0;
}
Sections:
Idx Name Size VMA LMA File ... 阅读全帖 |
|
d**d 发帖数: 389 | 3 好像明白了一些。
1. 一个函数,调用标准的C库,stdio.h什么的,如果C++的程序想要调用这个函数的话
,那么在编译的实际就有两种选择:
a, 存在.c 文件中,用gcc来编译,需要加extern "C"。
b, 存在.cpp文件中,把所有的 stdlib.h等等换成 cstdlib等等,用g++来编译,不需
要加 extern "C".
对不对? 对于情况b,是不是必须把所有的 stdlib.h等等换成 cstdlib等等?
如果不换的话,用g++来编译会有什么问题吗?C++里面的cstdlib是不是完全等同于
stdlib.h?
以前一个项目要么是C++,要不就是全是C的。现在有一个项目需要用到一些很老的C写
的库,以前写的时间,完全没有想到要给C++用的,搞的现在很麻烦,又没有人去把这
些库用C++从新写。
谢谢了。 |
|
T********i 发帖数: 2416 | 4 没有stdlib的多了,Cortex M哪有带stdlib的?内存只有那么几十K。
再说了,stdlib还要考虑平衡安全性,不能被恶意用户core dump之类。还有memory和
speed的trade off都不一样。
Cortex M连printf都要自己写。当然这并不意味着没有memory management。malloc还
是可以有的。我可以给你一个源码啊。
这些mcu本来就贼慢。中断优先级管好,内存慢慢管还是没问题的。内存管理和每秒钟
要处理上万次的interrupt都可以同时有啊。我做个in wall dimmer,就要提供每秒120
次的精确定时。还要有整个wireless协议栈。
+ |
|
T********i 发帖数: 2416 | 5 没有stdlib的多了,Cortex M哪有带stdlib的?内存只有那么几十K。
再说了,stdlib还要考虑平衡安全性,不能被恶意用户core dump之类。还有memory和
speed的trade off都不一样。
Cortex M连printf都要自己写。当然这并不意味着没有memory management。malloc还
是可以有的。我可以给你一个源码啊。
这些mcu本来就贼慢。中断优先级管好,内存慢慢管还是没问题的。内存管理和每秒钟
要处理上万次的interrupt都可以同时有啊。我做个in wall dimmer,就要提供每秒120
次的精确定时。还要有整个wireless协议栈。
+ |
|
l*****8 发帖数: 16949 | 6 下面这个hello world的20天能学会吗?
[
uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
]
library LHello
{
// bring in the master library
importlib("actimp.tlb");
importlib("actexp.tlb");
// bring in my interfaces
#include "pshlo.idl"
[
uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
]
cotype THello
{
interface IHello;
interface IPersistFile;
};
};
[
exe,
uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
]
module CHelloLib
{
// some code related header files
importheader();
importheader();
importheader(阅读全帖 |
|
D*****r 发帖数: 6791 | 7 http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html
High School/Jr.High
10 PRINT "HELLO WORLD"
20 END
First year in College
program Hello(input, output)
begin
writeln('Hello World')
end.
Senior year in College
(defun hello
(print
(cons 'Hello (list 'World))))
New professional
#include
void main(void)
{
char *message[] = {"Hello ", "World"};
int i;
for(i = 0; i < 2; ++i)
printf("%s", message[i]);
printf("\n");
}
... 阅读全帖 |
|
t*****n 发帖数: 5 | 8 In C programming, we usually include some standard library in the program,
such as , a question is: In VC++ platform, (1)where is the file <
stdlib.h> located? (2) can we see its source code and modify some part of its
content to produce a new customized header file? |
|
z****e 发帖数: 2024 | 9 #include
#include
#include
using namespace std;
后面用了abs()
error: call of overloaded ‘abs(double)’ is ambiguous
/usr/include/stdlib.h:691: note: candidates are: int abs(int)
没办法,把using namespace std;去掉,然后一个一个的using。编译通过了。
我估计是用了stdlib里边的abs,但是精度太差了。
怎么调用一个take double 的abs() 呢? |
|
c********t 发帖数: 27 | 10 1)
B=`echo "scale=4;4/3"| bc`
echo $B
1.3333
2)
#include
getenv and setenv
man getenv
man setenv
Note: Do not modify strings returned from getenv; they are pointers to
data that belongs to the system.
Or If you want to look into it.
#include
#include
int main(int argc, char *argv, char *envp[]){
while(1){
printf("%s\n", envp++);
}//segfault here
} |
|
j******g 发帖数: 1098 | 11 只有很简单的microcontroller上面跑的code,连stdlib都没有的才这么干,
比如这个code每秒钟要处理上万次的interrupt,那的确是baremetal的IRQ handler +
while loop + 静态变量。
没有stdlib会让开发很不方便,
如果只是每秒钟几十次或者几百次的响应,RTOS + 裁剪过的C++都可以。 |
|
j******g 发帖数: 1098 | 12 只有很简单的microcontroller上面跑的code,连stdlib都没有的才这么干,
比如这个code每秒钟要处理上万次的interrupt,那的确是baremetal的IRQ handler +
while loop + 静态变量。
没有stdlib会让开发很不方便,
如果只是每秒钟几十次或者几百次的响应,RTOS + 裁剪过的C++都可以。 |
|
r****y 发帖数: 1437 | 13 【 以下文字转载自 Programming 讨论区 】
【 原文由 rossby 所发表 】
我写了个程序,两个,几乎一模一样,但是一个在UNIX下给出正确
结果另外一个segmentation fault . 到Linux 下一试,还是一样.晕了.
给出正确结果的程序
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "sys/time.h"
void main (int argc, char *argv)
{
int i, j;
struct timeval *tp;
struct timezone *tz=NULL;
i = gettimeofday(tp, tz);
printf("flag %d\n ", i);
printf("time %ld\n", tp->tv_sec);
printf("time %ld\n", tp->tv_usec);
}
segmentation fault的程
#include "stdio.h"
#include "stdlib.h"
#i |
|
a****s 发帖数: 2060 | 14 转
#include
#include
#include
#include
void main()
{
int a=0,b=0,c=0;
int A=0,B=0,C=0;
int num=0;
while(1)
{
while(A+b==3 && B+a==1 && A+c==6 && C+a==4 && C+b==7)
{
cout<
cout<
cout<
cout<
cout<
cout<
return;
}
a=rand()%10;
b=rand()%10;
c=rand()%10;
A=rand()%10;
B=rand()%10;
C=rand()%10;
}
} |
|
d****o 发帖数: 32610 | 15 汉语是个古老的编程语言
在此之上有标准函数库,官方版本由中国维护
因为中国古代牛逼,周边国家大都fork过,然后搞了自己的版本
时间久了,自然就有了差异
随着时代发展,西方崛起
搞出了很多新的牛逼算法
鬼子留学早,先接触了这些东西,
就拿自己熟悉的语言实现了这些函数,
然后放在自己的标准库里
中国发现好用,就在后来的新标准版本里也加上了一样的东西
具体到“党“这个例子
汉语标准库也有党这个函数
后来西方弄出了现代政党政治
拿python做了个party函数
日本发现好用
怎么办呢
因为汉语支持function overload
为了方便
就把汉语本来的党函数overload了
重新写了个跟party函数一样的c++版本
中国一看不错
也放到stdlib里了 |
|
f*********0 发帖数: 861 | 16 还是到这个版来问问.
快崩溃了, 怎么也run不起来, 不知道哪里有问题.
#include
#include
int main()
{
float grade1;
float grade2;
float grade3;
printf("enter your 3 test grades: n");
scanf(" %fn", &grade1);
scanf(" %fn", &grade2);
scanf(" %fn", &grade3);
float avg =(grade1 + grade2 + grade3)/3;
printf("average: %.2fn", avg);
if(avg >=90){
printf("grade: A");
}else if(avg >=80){
printf("grade: B");
}else if(avg >=70){
printf("grade: C");
}else if(avg >=60){
printf("grade: D");
}else{
prin... 阅读全帖 |
|
a**u 发帖数: 59 | 17 // Vote.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
#include
#include
#pragma comment(lib, "wininet.lib")
int vote3(void);
void vall3(void *);
int v3;
int main(int argc, char* argv[])
{
unsigned int k,i;
if(argc==1) i=100;
else i = atoi(argv[1]);
printf("%d threads (for each vote) will be opened! \n", i);
for(k=0;k |
|
w********p 发帖数: 948 | 18 code is here, I run it simply, it looks good
O(n) for running time, and O(1) for space
#include
#include
#include
using namespace std;
int SumKMember(int iArray[],int startIndex, int endIndex, int sum);
int main (int argc, char *args[]) {
if (argc != 2) {
cout<<"comment line: a.exe number\n";
return 0;
}
int k=atoi(args[1]);
//n is the array size
int maxSum=-99999999;
int iArray[] = {1, 2 , 4 , -3, 5 ,2};
int n = sizeof( iArray) /sizeof |
|
n**x 发帖数: 30 | 19 写得有点恶心,细节没有优化。后半部分感觉可以优化掉,但不知道怎么证明。
#include
#include
inline int IsOdd(int x){
return (x&1)==1;
}
inline int IsEven(int x){
return (x&1)==0;
}
int getmedian(int *s1,int *e1,int *s2,int *e2){
int N1=(e1-s1),N2=(e2-s2);
int N=N1+N2;
int NHalf=(N1+N2)>>1;
float m1,m2;
int remainHead=0,remainTail=0;
while(remainHead
N1=(e1-s1);
N2=(e2-s2);
if(IsOdd(N1)) m1=s1[N1>>1];
else m1=(s1[(N1>>1)-1]+ |
|
k*k 发帖数: 49 | 20 this should work... O(n * (n k)) where k is the range of elements. if we
only check k from 1 to s such as that s + i <= n then, the complexity
becomes n^3.....
not sure this is the most efficient....
#include
int jump(int* arr, int n){
int idx[n];
int edge[n];
int i = 0;
int j = 0;
idx[0] = 0;
for(i=1; i
int min = i;
int minidx = -1;
for(j=i-1; j>=0; j--){
int k = 0;
for(k=1; k<=arr[j]; k++){
if (arr[j]!=-1 && k+j==i){
if (idx |
|
k*k 发帖数: 49 | 21 #include
void swap(char* arr, int f, int t){
char tmp = arr[f];
arr[f] = arr[t];
arr[t] = tmp;
}
void permute(char *str,int start){
int i;
if(start==strlen(str)-1)
printf("%s\n",str);
for(i=start;i
if(start != i && str[i]==str[start])
continue;//eliminate duplicates
swap(str, i, start);
permute(str,start+1);
swap(str, i, start);
}
}
int main(){
char str[] = "1233";
permute(str, 0);
}
$ ./pm | wc -l
22
but sh |
|
g****y 发帖数: 436 | 22 源代码就是一个2d数组的分配和删除:
编译运行以后发现,程序占用内存按照 4K/单位时间 的速度增加,请问这是怎么回事
呢?
#include
#include
int main()
{
while(1){
int i; /* general purpose variable used for loop index */
int j; /* general purpose variable used for loop index */
int **a; /* this is the array name */
int size_x; /* this variable will be used for the first dimension */
int size_y; /* this variable will be used for the second dimension */
/* suppose we want an array of int: a[5][3] */
size_x = |
|
g****y 发帖数: 436 | 23 下面这个代码更能说明问题,内存占用上升到了几百M
#include
#include
int main()
{
int gaga = 10000000;
while(gaga-- > 0){
int i; /* general purpose variable used for loop index */
int j; /* general purpose variable used for loop index */
int **a; /* this is the array name */
int size_x; /* this variable will be used for the first dimension */
int size_y; /* this variable will be used for the second dimension */
/* suppose we want an array of int: a[5][3] */
size_x = |
|
c**y 发帖数: 172 | 24 Below is my code. However, (101,2)^2 looks the simplest.
#include
#include
#include
using namespace std;
int countRect(int x, int y) {
if ((x == 0) || (y == 0)) {
return 0;
} else if ((x == 1) && (y > 1)) {
return y;
} else if ((x > 1) && (y == 1)) {
return x;
} else {
return (x * y);
}
}
int countAllRect(int n, int m) {
if ((n <= 0) || (m <= 0)) {
return 0;
} else if ((n == 1) && (m > 1)) {
|
|
t****a 发帖数: 1212 | 25 O(n^2) DP solution here:
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
int a[] = {4,6,1,7,2,10,8,5,3,9};
const int n = 10;
int sum[n][n];
int best[n][n];
int game(int a[], int start, int stop) {
if (start > stop) {
return 0;
} else if (best[start][stop]!=-1) {
return best[start][stop];
} else {
int s1 = sum[start+1][stop] - game(a, start+1, stop) + a[start];
int s2 = sum[start][stop-1] - game(a, start, stop-1) + |
|
UD 发帖数: 182 | 26 below code seems to work, and should be O(n) time and O(1) space, if you disagree, please list your argument.
The idea behind is the use and resue of sum(i,j), that's why the O(1) space.
sum(i,j)=sum of all the 1s between i and j.
sub-seq(i,j) has equal 1s and 0s when sum(i,j)*2=j-i+1, we start by setting i=0,j=A.length-1, then searching from both ends.
1. if sum(i,j)*2==j-i+1, then found it
2. else if sum(i,j)*2>j-i+1, we have more 1s then 0s, then we check A[i] and A[j]:
a. if A[i]==A[j], t... 阅读全帖 |
|
t****a 发帖数: 1212 | 27 han6 come first
qu you wu, zhou lang gu :)
here goes DP solution, as han6 said, O(m^3)
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
int cost[100][100];
int best_cut(int position[], int start, int stop) {
// printf("%d\t%d\n", start, stop);
if (cost[start][stop]!=-1) {
return(cost[start][stop]);
} else {
int cost0 = position[stop] - position[start];
if (start+1 == stop) {
cost[start][stop] = cost0;
|
|
c***2 发帖数: 838 | 28 Here's the full file. You may compile and run: any case I missed?
==================================================================
/* wild.c
*/
#include
#include
#include
#define STR_SIZE 256
//===========================================================
int matchndots(const char *text, const char *dstr, int len)
{
while(len&&*text&&*dstr&&(*text==*dstr || *dstr=='.')){
text++;
dstr++;
len--;
}
if(!len)
return 1;
... 阅读全帖 |
|
o*****e 发帖数: 99 | 29 Sigh...,
Why are so many misleading information here.
You guys really should try it out before post here.
char* c;
is not a "declare" in this case, it is a definition.
since the stack will allocate 4bytes(8bytes for 64bit machine) for it.
And you don't have to initialize this pointer if you decide to give it a
value in foo().
#include
#include
void foo(char** a){
static char A[20] = "hello world";
*a = A;
}
int main(){
char* c;
foo(&c);
printf("%s",c);
... 阅读全帖 |
|
i******s 发帖数: 301 | 30 你的解法应该是对的,基于这个写了如下C++代码
/*
* Author: Shengzhe Yao
* Date: 08 Nov 2010
*/
#include
#include
#include
#include
using namespace std;
// T(n) = \sum_{i=1}^{n-1} (T(i) * H(i+1))
int findAllStr(const set &dict, char *str,
int end, int *lookup_table) {
if (lookup_table[end] > 0)
return lookup_table[end];
int total = 0;
for (int i=1; i < end; ++i) {
char *substr = (str+i+1);
if (dict.find(substr) != dict.end()) {
char tmp =... 阅读全帖 |
|
c***2 发帖数: 838 | 31 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... 阅读全帖 |
|
J******8 发帖数: 132 | 32 The question is not hard. But I missed two key points.
The details below.
==========================================================
/*
example
char *words[] = {"foo", "bar", "baz", NULL};
setup(words);
1) First step:
isMember("foo") -> true
isMember("garply") -> false
2) Second step:
isMember("f.o") -> true
isMember("..") -> false
*/
#include
#include
#include
char *words[] = {"foo", "bar", "baz", "caz","cat",NULL};
int num=0;
void print_words(void)
{
int i=0... 阅读全帖 |
|
b*****e 发帖数: 474 | 33 很不错了。细节可以再推敲一下,算法本身(基于DFS的递归)没问题,C++
的掌握也不错。当个 developer 够了哈。
我的版本,给你参考一下吧:
#include
#include // i like arrays
#include // for atoi()
using namespace std;
void print_parens(int n) {
static vector s; // i just use static vars to save parameter
static numLeft = 0; // passing
static numRight = 0;
if (n<0) return;
if (n==0) {
for( int i=0; i
// save the extra recursion when there are n '('s already -
// so ... 阅读全帖 |
|
f****g 发帖数: 313 | 34 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... 阅读全帖 |
|
n********y 发帖数: 66 | 35 欢迎拍砖,就用了一个 256 字节的table来检查一个数字是否出现过
#include
#include
#include
#include
char* nextpointer(char* str, int strlen)
{
char *p = str;
char *pend = str + strlen;
char count[256];
memset(count, 0, sizeof(count));
while (p < pend)
{
++count[*p];
if (count[*p] > 1)
{
return p;
}
++p;
}
return p;
}
void longestsingle(char* str, int strlen)
{
char *pstart = str;
char *pend... 阅读全帖 |
|
s*****y 发帖数: 897 | 36 看了各位大牛的实现后,写了个O(nlgk)的C实现
#include
#include
//assume input array size < 20
#define ARRAY_SIZE 20
/*P[k] —stores the position of the
predecessor of X[k] in the longest increasing subsequence ending at X[k].*/
static int P[ARRAY_SIZE];
/*M[j] stores the position k of the smallest value X[k]
such that there is an increasing subsequence of length j ending
at X[k] on the range k ≤ i (note we have j ≤ k ≤ i here)*/
static int M[ARRAY_SIZE];
void Find_Lis(int input[], int size, int... 阅读全帖 |
|
p*********b 发帖数: 47 | 37 9,Unix file path化简,写code
例如 /a/./b/../../c/ ,化简为 /c/
用stack或者d-queue,有些细节需要考虑,例如 /..//.. 还是输出 /
这题不需要额外的数据结构,从尾部向前反过来做。
我之前写的代码
/* The algorithm runs in O(n) time and O(n) space
* It works backwards so that no stack or other buffer is
* needed to skip the parents folder if a "../" is encountered.
* "//" is preserved as is, and "/./" is changed to "/
* I was able to do a inplace version, but string cut and cat are
* essentially array element revomal, which will make running time
* O(n^2).
*
* My ... 阅读全帖 |
|
o****d 发帖数: 2835 | 38 来自主题: JobHunting版 - 问个面试题 C程序
思路如上面的朋友所说
=======
#include
#include
void setMatrix (int ** matrix, int x, int y, int n, int start)
{
int i,j;
if(n==0)return;
else if(n==1) matrix[x][y]=start;
else{
for(j=y;j
matrix[x][j]=start++;
for(i=x;i
matrix[i][y+n-1]=start++;
for(j=y+n-1;j>y;j--)
matrix[x+n-1][j]=start++;
for... 阅读全帖 |
|
s*****y 发帖数: 897 | 39 来自主题: JobHunting版 - 问个编程题 #include
#include
#include
#include
using namespace std;
vector FindSet(int target, const vector &input)
{
vector rtn;
int dp[10][100]; //dp table to save the result
bool used[10][100];
for (int i = 0; i <= target; i++) {
dp[0][i] = 0;
if (i <= 1) {
dp[1][i] = i;
used[1][i] = true;
} else {
dp[1][i] = INT_MAX;
used[1][i] = false;
}
}
for ... 阅读全帖 |
|
l*********8 发帖数: 4642 | 40 #include
#include
int main(int argc, char * argv[])
{
char * s[4] = {"000", "Fizz", "Buzz", "FizzBuzz"};
char buf[4];
for (int x=1; x<=100; x++) {
s[0] = itoa(x, buf, 10);
printf("%s\n", s[ !(x%3) + 2*!(x%5) ] );
}
return 0;
} |
|
a***r 发帖数: 93 | 41 My solution is about the same as bitwise, it uses an array:
#include
#include
void add_range(int D[], int l, int a, int b) {
if(b
for (int i=a; i<=b; i++) {
D[i%l]+=1;
}
}
bool is_overlap_array(int a,int b,int c,int d) {
int D[7]= {};
int l=sizeof(D)/sizeof(D[0]);
add_range(D,l,a,b);
add_range(D,l,c,d);
for (int i=0; i
if (D[i]>1) { return true; }
}
return false;
}
void main(int argc, const char *... 阅读全帖 |
|
S**I 发帖数: 15689 | 42 #include
#include
#include
struct StringCount{
char s[100];
int count;
};
int compare(const void * a, const void * b){
return ((*(struct StringCount *)a).count < (*(struct StringCount *)b).count);
}
void printSortedWords(char * s, FILE * file){
int size = strlen(s);
struct StringCount sc[100];
int num = 0;
char newstr[100];
int i = 0;
for(; i < size; i++){
if(s[i] != ' '){
int j = 0;
while(s[i]... 阅读全帖 |
|
m****t 发帖数: 555 | 43 我的程序运行结果是正确的。
这个c程序输出就是 pylhssrtnaatareyeopsfefasmeietawodny
#include
#include
#include
int main()
{
char *A="paypalisthefastersaferwaytosendmoney";
char B[4][10]={};
int ROW = 4;
int COL;
int N;
COL = strlen(A)/ROW;
if (strlen(A)%ROW) {
COL++;
}
N= strlen(A);
int pos=0;
int c, xb=0;
int x, y;
for (c=0; c<= ROW+COL-2; c++) {
x = xb;
y = c-x;
while (x >= 0 && y <= COL-1 && pos
B[x][y] = A[pos];
pos++;
x--;
y++;
}
if (xb < ROW... 阅读全帖 |
|
s*****y 发帖数: 897 | 44 写了个简单的,解你这个例子的,
#include
#include
#include
#include
#include
#include
using namespace std;
int matrix[4][4] = {{5,0,0,0},
{9,6,0,0},
{4,6,8,0},
{0,7,1,5}};
int getMax()
{
vector dp_table(4, 0);
for (int i = 0; i < 4; i++)
dp_table[i] = matrix[3][i];
for (int j = 2; j>= 0; j--) {
for (int i = 0; i <= j; i++)
dp_table[i] = max(matr... 阅读全帖 |
|
h********r 发帖数: 51 | 45 下面这个方法行不行? O(n), 模拟一次买卖的DP解法。大牛们看看对不对?
#include
#include
#include
void dump(int *x, int l) {
int i;
for (i = 0; i < l; ++ i) {
printf("%d ", x[i]);
}
printf("\n");
}
int main() {
int array[] = {3, 6, 8, 4, 5, 7, 9, 13, 15, 10, 6, 2, 7, 11, 8, 6};
int len = sizeof(array)/sizeof(int);
assert (len >= 4);
int *a = (int*)malloc(sizeof(int)*len);
int *b = (int*)malloc(sizeof(int)*len);
int *c = (int*)malloc(sizeof(... 阅读全帖 |
|
|
s******e 发帖数: 108 | 47 update:
收到invite onsite 通知,恩,国人还是挺靠谱的。感谢。
感谢NND的推荐,
不过可能被interviewer的国人给干掉了.
1.经典的stream求median,用2个heap解决。
2.给了一段程序,说一下程序的功能,
然后比较c程序和javascrip程序的区别。这个down掉。
#include
#include
#include
#include
#define MAX_RETRY 3
int remoteCall() {
return random() % 2;
}
void action(times) {
printf("calling remote procedure\n");
if (remoteCall()) {
printf("success!\n");
} else {
printf("error occured!\n");
if (times < MAX_RETRY) {
sleep(1);
... 阅读全帖 |
|
z****u 发帖数: 104 | 48 字符串的 permutation 肯定是比较基础的题了,可是自己写了一下发现要 bug free
真心很难啊。调试了半天才 ok,而且程序看起来很臃肿,这要是在白板上铁定写不出
来啊
求大家指点一下该向哪个方向改进?
#include
#include
#include
char* insert(char* dst, int n, char c, int j)
{
/* Insert char c into string dst at location j */
n++;
dst = (char*) realloc(dst, sizeof(char) * n);
while(j < n)
{
char tmp = dst[j];
dst[j] = c;
c = tmp;
j++;
}
return dst;
}
char** permutation_recursive(char* s, int n, in... 阅读全帖 |
|
L**********u 发帖数: 194 | 49 This problem can be solved by binary representation of an integer.
I am a rookie of C++. thanks for comments
my codes
#include
#include
#include
using namespace std;
const int N=5;
void subset(int arr[], int n)
{
bitset n_bit(n);
cout<<"{";
for(int i=0;i
if(n_bit[i]==1)
cout<
cout<<"};";
cout<
}
//main function
int main()
{
cout<<"The set has "<
int arr[N];
for(int i=0;i
arr[i]=... 阅读全帖 |
|