i*****o 发帖数: 105 | 1 #include
#include
int x[10][10] = {
{ 1, 1, 1, 1, 1, 1, 5, 1, 1, 1,},
{ 1, 1, 1, 1, 1, 1, 4, 1, 1, 1,},
{ 1, 1, 1, 1, 1, 1, 8, 1, 1, 1,},
{ 1, 1, 1, 1, 5, 4, 10, 1, 1, 1,},
{ 1, 1, 1, 1, 4, 1, 10, 10, 1, 1,},
{ 1, 1, 1, 1, 5, 5, 10, 10, 10, 10,},
{ 1, 1, 5, 6, 1, 5, 11, 1, 1, 1,},
{ 1, 1, 3, 1, 1, 1, 10, 1, 1, 1,},
{ 1, 2, 2, 1, 1, 1, 1, 1, 1, 1,},
{ 2, 1, 10, 10,... 阅读全帖 |
|
D*****r 发帖数: 6791 | 2 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");
}
... 阅读全帖 |
|
x****o 发帖数: 21566 | 3 /* Source Code Windows 2000 */
#include "win31.h"
#include "win95.h"
#include "win98.h"
#include "workst~1.h"
#include "evenmore.h"
#include "oldstuff.h"
#include "billrulz.h"
#include "monopoly.h"
#include "backdoor.h"
#define INSTALL = HARD
char make_prog_look_big(16000000);
void main()
{
while(!CRASHED)
{
display_copyright_message();
display_bill_rules_message();
do_nothing_loop();
if (first_time_installation)
{
make_100_megabyte_swapfile();
do_nothing_lo... 阅读全帖 |
|
发帖数: 1 | 4 http://rosettacode.org/wiki/24_game/Solve#C
改一下就行了。这是输入4个的,可以改成输入3个的。
6 17 3 7: No solution
……
#include
#include
#include
#define n_cards 4
#define solve_goal 29
#define max_digit 9
typedef struct { int num, denom; } frac_t, *frac;
typedef enum { C_NUM = 0, C_ADD, C_SUB, C_MUL, C_DIV } op_type;
typedef struct expr_t *expr;
typedef struct expr_t {
op_type op;
expr left, right;
int value;
} expr_t;
void show_expr(expr e, op_type prec, int is_r... 阅读全帖 |
|
b*****l 发帖数: 9499 | 5 有木有!!!!!!!!!!!!!!!!!
还是不能设 thread 数目。去掉相应行,work 了,但每次跑起来,threads 数目不等
,看系统的心情。跑了三次,分别是 15,17,16 个 threads.
#include
#include
int main () {
omp_set_dynamic(1);
printf("omp_get_dynamic: %d.\n",omp_get_dynamic());
printf("omp_get_max_threads: %d.\n", omp_get_max_threads());
/* omp_set_num_threads(10); */
/* Fork a team of threads with each thread having a private tid variable */
printf("Fork! \n");
#pragma omp parallel
{
// Obtain and print thread id
printf(... 阅读全帖 |
|
f*********0 发帖数: 861 | 6 快崩溃了, 怎么也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{
printf("you are fai... 阅读全帖 |
|
f**********d 发帖数: 4960 | 7 来自主题: Programming版 - c的问题 试了报错,其实我是要逐行读入文件,并把每一行用";"分隔成不同fields,再把
fields存入array里。
文件第一行是header,之后每行为 v1;v2;v3;v4;v5
现在*Words[j] = *pch;报错了,说access violation writing location 0xccccccccc.
fp = fopen("Data Files\ChestClinic.txt", "r");
if (fp == NULL)
{
printf("file is null");
}
i = 0;
while (fgets(line, sizeof(line), fp))
{
if (i == 0)
{
printf("The format of network structure file is:n");
printf("%sn", line);
... 阅读全帖 |
|
h*****t 发帖数: 40 | 8 Yes, I did run from web browser
the results is:
blah blah blah
...
whoami = "my username"
I am sorry for my native Question.
environ.cgi
#! /usr/local/bin/perl
printf "Content-type: text/html\n\n";
printf " environ.cgi \n";
printf "Query Results";
printf "You submitted the following %%ENV pairs:\n \n";
foreach $item (sort(keys %ENV))
{ printf "- CGI variable : %s Value : %s
\n", $item, $ENV{$item};
}
printf " \n";
printf "w |
|
|
j*****g 发帖数: 223 | 10 // txt -> text
// p -> pattern (include . and *)
void pattern_match(const char *txt, const char *p)
{
int **d = NULL;
int len_txt = 0, len_p = 0;
int i, j, k;
if (!txt || !p) goto exit;
len_txt = strlen(txt);
len_p = strlen(p);
if (len_txt == 0 || len_p == 0) goto exit;
printf("text : %s\n", txt);
printf("pattern: %s\n", p);
d = new int*[len_p];
if (!d) goto exit;
memset(d, NULL, sizeof(int*) * len_p);
for (i = 0; i < len_p; i++)
{
... 阅读全帖 |
|
s*******f 发帖数: 1114 | 11 //A. Given an arbitrary tree, can you print it level by level (with each
level
//printed on the same line).Define your own tree node structure, can be
//binary tree or n-ary tree.
struct Node{
int d;
std::vector children;
};
void PrintByLevel(Node *r){
if (!r)
return;
std::queue q;
q.push(r);
int pre_count = 1;
int count = 0;
while (!q.empty()){
Node *p = q.front();
for (std::vector::const_iterator ci = p-
>children.begin(); ci != p->children.end(); ++ci){
q.push(*ci);
++cou... 阅读全帖 |
|
k***t 发帖数: 276 | 12 我也试一个,in-placed的。先把要删掉的mark成'*'。第二次遍历时再删掉。
#include
// /a/b/./../../c/d => /c/d
void path (char *in) {
char *p, *q;
bool isSlash;
char inv='*';
if (!in || !*in) return;
int i=0;
// parse
p=in; isSlash=false;
while (*p) {
/* first slash */
if (*p=='/') {
if (!isSlash) {
isSlash=true;
} else {
*p=inv;
}
p++; continue;
}
isSlash=false;
... 阅读全帖 |
|
f*****y 发帖数: 444 | 13 I am preparing algorithm, wrote the following algorithm. Share with you. Not
sure whether it is a duplicate post or not.
//---- Breadth Fast Search algorithm ---
// circular queue
int head = 0;
int tail = 0;
#define Q_EMPTY (head==tail)
#define Q_FULL ((tail-head+1)%SIZE==0)
#define SIZE 10
struct Node* q[SIZE];
void put(struct Node* x)
{
if (x==NULL) return;
if (Q_FULL) return; //queue full
q[tail] = x;
tail = (tail+1) % SIZE;
return;
}
struct Node* get()
{
if (Q_EMPT... 阅读全帖 |
|
s******n 发帖数: 3946 | 14 他的意思是假设是operator重载
++i先做++再放在stack上,i++则先复制一份copy到stack上再做++,多了一份复制(假
设编译无优化)
大家看有道理吗?
I did a real test on arm compiler turn off optimization:
the O0 code is exactly the same, except that post operator++()(int dummy)
has an extra dummy parameter which is required by c++ to identify the
difference of prefix and postfix.
2nd, even I change the Test& operator++() into Test operator++(), it still generates the same code.
printf("%d \n", 10+ (abc++).value);
sub r3, fp, #8
mov r0, ... 阅读全帖 |
|
s******n 发帖数: 3946 | 15 the O0 code is exactly the same, except that post operator++()(int dummy)
has an extra dummy parameter which is required by c++ to identify the
difference of prefix and postfix.
2nd, even I change the Test& operator++() into Test operator++(), it still generates the same code.
printf("%d \n", 10+ (abc++).value);
sub r3, fp, #8
mov r0, r3
mov r1, #0 --> the dummy parameter of postfix
bl _ZN4TestppEi
mov r3, r0
ldr r3, [r3, #0... 阅读全帖 |
|
s******n 发帖数: 3946 | 16 写个循环的,思路和lz是一样的,同样的三个分支判断:1行/1列/多行多列
void print(int **a, int M, int N)
{
int l = 0;
int r = M-1;
int t = 0;
int b = N-1;
while (l<=r && t<=b) {
if (l==r) {
for (int i=t; i<=b; i++) printf("%d ", a[i][l]);
} else if (t==b) {
for (int i=l; i<=r; i++) printf("%d ", a[t][i]);
} else {
for (int i=l; i
for (int i=t; i
for (int i=r; i>l; i--) printf("%d ", a[b][i]);
for (int i=b; i
}
l++;r--;
t++... 阅读全帖 |
|
l*********8 发帖数: 4642 | 17 完整的程序:
cat list.txt | awk -F \| \
'{a[$1]; b[$2]; t[$1]+=$4; c[$1,$2] += $4} \
END{ \
printf "Total revenue by customer:\n"; \
for(x in a) {\
printf x; \
printf " - $%.2f\n",t[x]; \
} \
for (x in a) {\
printf "\nPurchases by %s\n", x; \
for (y in b) { \
if (c[x,y] > 0) {\
printf y; \
printf " - $%.2f\n", c[x,y]; \
}\
}\
}\
}'
输出:
Total revenue by customer:
Pedro - $11.02
Susie - $70.1... 阅读全帖 |
|
J**9 发帖数: 835 | 18 高手很多呀
看起来容易, 写起来难
It must be two passes unless you copy things to another array or list.
Here's my version in C:
void hkStringPrintMaxCounts(char *s)
{
if (!s || !(*s)) return;
int table[256] = {0};
char *p = s;
int max=1;
int count=1;
int index=0;
char c=*p;
printf("%s():\n", __FUNCTION__);
/// First pass: count and find max
while(*p)
{
c=*p;
count=0;
while(*p == c)
{
count++;
p++;
in... 阅读全帖 |
|
R*****i 发帖数: 2126 | 19 这个题目建议用红黑树做可能最快捷有效。红黑树每一次插入,删除都是log(k),求平
均值非常简单,就是根部的那个节点。所以总的计算量是O(nlog(k))。
以下是c/c++代码(需要修改数组,以便一个一个输入)。
#include
#include
#include
#define INDENT_STEP 4
enum rbtree_node_color {RED, BLACK};
typedef struct rbtree_node_t {
int value;
struct rbtree_node_t* left;
struct rbtree_node_t* right;
struct rbtree_node_t* parent;
enum rbtree_node_color color;
} *rbtree_node;
typedef rbtree_node node;
typedef enum rbtree_node_color color;
typedef struct... 阅读全帖 |
|
J**9 发帖数: 835 | 20 Problem at
http://discuss.leetcode.com/questions/765/word-break
This does not seem to be a DP problem, just do it in a straightforward way.
Here's my implementation in C. Any issue?
Thanks.
//===========================================================
#include
#include
#include
#include
#include
/**
* Given a string s and a dictionary of words dict, determine if s can be
segmented into a space-separated sequence of one or more
* dictionary w... 阅读全帖 |
|
|
|
r****8 发帖数: 22 | 23 networking背景。和web公司的风格不大一样。多个公司的面筋。希望对后来人,有帮
助。
implement a hash table
lru cache
two sum
void store(int val);
store the value
bool test(int target);
return true if two stored values who sum equals target
otherwise false
We want test really fast.
O(1) test
O(n) store
Given a binary tree where parent node value is minimum of two children node
values, find the second min.
given nested list, return sum. Sum is defined as depth*current sum
what is dead lock? how to prevent it?
implement a readlock
im... 阅读全帖 |
|
i*****o 发帖数: 105 | 24
This is cool, the code is ugly:
#include
int
has3bits(unsigned c)
{
int n = 0;
while (c) {
n += (c&1);
c >>= 1;
if(n > 3) {
break;
}
}
return n == 3;
}
unsigned
highbit(unsigned c)
{
unsigned h = 0x100;
while (!(h & c) && h) {
h >>= 1;
}
return h;
}
int
c3_next(unsigned *c1, unsigned *c2)
{
unsigned c1_min = 0x100, c2_min;
int found = 0, found1 = 0;
while (!found) {
if (has3bits(*c1... 阅读全帖 |
|
l***y 发帖数: 4671 | 25 用 perl 开一个多线程,每个线程分别实时逐行报告状态,想既在屏幕上显示,又同时
分别输入到 log 文件中去。咋整涅?
狗了很多,最接近的办法是在线程里写:
sub mythread ($){
...
my $rc = system("myprogram blah blah blah | tee LOG_$_[0].txt");
...
}
这个方法的问题是没法实时逐行在屏幕上显示,而是把 myprogram 的输出分三次显示
出来。。。
为啥会分三次涅?。。。俺的c++ 程序里的输出命令都是 printf 啊,分别在三个
loops 里。大约长相是:
第一个循环 A:
if (dbg_parameter){
printf("\n\33[32;40m Parameters got from file "%s": \33[0m \n", sParFile.c
_str());
for (map::iterator it = p.begin(); it != p.end(); it++)
printf("\tp["%s"]... 阅读全帖 |
|
e********d 发帖数: 1202 | 26 #include
main(int agrc, char * argv[]){
int a = 4;
printf("%f\n",a);
printf("%u\n",a);
printf("%f,%u\n",a,a);
printf("%d,%f,%u\n",a,a,a);
printf("%d,%f,%u,%u\n",a,a,a,a);
printf("%f,%u\n",(float)a,(unsigned)a);
}
gcc, mac osx, 输出如下,
0.000000
4
0.000000,2413823420
4,0.000000,0
4,0.000000,4,0
4.000000,4
请教中间几行输出为什么是这样. |
|
P********e 发帖数: 2610 | 27 %f读4,如果是按照float格式读,是接近0的一个数 e - 128?之类的
你可以把4 cast 到float,然后再看byte representation. exp的位有一个127的offset
%u读a, 我比较奇怪为什么不是4,解释不了
而且,倒数第二行,同样%u%u,第一次是4,第二次0
#include
main(int agrc, char * argv[]){
int a = 4;
printf("%f\n",a);
printf("%u\n",a);
printf("%f,%u\n",a,a);
printf("%d,%f,%u\n",a,a,a);
printf("%d,%f,%u,%u\n",a,a,a,a);
printf("%f,%u\n",(float)a,(unsigned)a);
}
gcc, mac osx, 输出如下,
0.000000
4
0.000000,2413823420
4,0.000000,0
4,0.000000,4,0
4.000000,4
请教中间几行输出为什么是这样. |
|
d****n 发帖数: 1637 | 28 Sorry something was wrong from googled.
here is my test.
#include
#include
int main(){
char const * p ="Hello";
char q[]="York";
printf("%p\n",p);
p=q; //okay
printf("%p\n",p);
const char *k="two";
printf("%p\n",k);
k=q; // okay
printf("%p\n",k);
char * const s="one";
printf("%p\n",s);
s=q; //segfault
printf("%p\n",s);
} |
|
s******n 发帖数: 3946 | 29 【 以下文字转载自 JobHunting 讨论区 】
发信人: swanswan (swan), 信区: JobHunting
标 题: 有个SB interviewer和我说++i比i++好
发信站: BBS 未名空间站 (Thu Mar 22 16:09:09 2012, 美东)
他的意思是假设是operator重载
++i先做++再放在stack上,i++则先复制一份copy到stack上再做++,多了一份复制(假
设编译无优化)
大家看有道理吗?
I did a real test on arm compiler turn off optimization:
the O0 code is exactly the same, except that post operator++()(int dummy)
has an extra dummy parameter which is required by c++ to identify the
difference of prefix and postfix.
2nd, even I change the Test& ope... 阅读全帖 |
|
k****e 发帖数: 126 | 30 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 ... 阅读全帖 |
|
W*****x 发帖数: 684 | 31 你把代码贴上来看看。。。
1 #include
2
3 int main(void)
4 {
5 char p_ch[3] = {'a', 'b', 'c'};
6 char *p_str[3] = {"a", "b", "c"};
7
8 printf("p_ch[1] = %c\n", p_ch[1]);
9 printf("p_ch[1] @ %p\n", &p_ch[1]);
10 printf("p_ch[1] @ %p\n", p_ch+1);
11
12 printf("p_str[1] = %s\n", p_str[1]);
13 printf("p_str[1] @ %p\n", &p_str[1]);
14 printf("p_str[1] @ %p\n", p_str+1);
15
16 return 0;
17 }
p_ch[1] = b
p_ch[1] @ 0... 阅读全帖 |
|
d***e 发帖数: 793 | 32 We are not finding the longest substring here. so any longest subsequence
will do.
This method scans twice which is O(n) and use no buffer only integer
variables which O(1)space.
void getSubseq(int *array, int len){
int maxLen = 0;
int ctZero = 0, ctOne = 0;
for(int i=0;i
printf("%d ", array[i]);
if(array[i]==0) {
ctZero++;
}
else ctOne++;
int min = ctOne
if(min>maxLen){
maxLen ... 阅读全帖 |
|
d******a 发帖数: 238 | 33 有2, 3, 5 面值的多个硬币,给定一个值,打印出所有的组合。
这道题出现过在facebook, microsoft的面试中,还是很经典的。我的思路就是先用面
值最大的,可以有0到m个,然后再依次用面值次小的,依此类推。下面这个程序就是这
个想法,但感觉并不是很简单。
不知道大家有什么好想法?
void make_change_help(int n, int *result, int index, int demon)
{
int next_demon = 0, i;
if(n < 2)
return;
if(n == 0)
{
for(i = 0; i < index; i++)
printf("%d ", result[i]);
printf("\n");
return;
}
if(demon == 5)
next_demon = 3;
else if(demon == 3)
next_de... 阅读全帖 |
|
l****c 发帖数: 838 | 34 You should read in the string and parse.
You don't know how long the first part string is or how long the number is.
So if you define:
char tempprice[10];
char ticker[10];
You have the risk of buffer overflow.
Here is my solution. I debug it as I wrote it, so it is not optimized.
it is pure C. You can get result with 2 lines of perl or python code
============================
#include
#include
#include
int main()
{
char *str = "GOOD|89.34";
char *ptoken, *... 阅读全帖 |
|
c**y 发帖数: 172 | 35 特殊字符就是()
以下是个inorder的例子
printf("(");
inrodervisit(p_node->p_leftchild);
printf(")");
printf(p_node->value);
printf("(");
inrodervisit(p_node->p_rightchild);
printf(")");
这样每次访问一个新的subtree,总是会打印一个()surrounding这个subtree的序列
。 |
|
A*****o 发帖数: 284 | 36 献丑发个代码, 遍历两数乘积的因子组合, 同时需要控制下打印范围:
#include
#include
#include
using namespace std;
int n;
void printPair(int a, int b) {
int m = a * b;
int x, y;
for (x = m/max(a,b); x <= (int)sqrt(double(m)); x++) {
if (m%x == 0) {
y = m / x;
printf("%d * %d = %d * %d\n", a, b, x, y);
printf("%d * %d = %d * %d\n", a, b, y, x);
printf("%d * %d = %d * %d\n", b, a, x, y);
printf("%d * %d = %d * %d\n", b, a, ... 阅读全帖 |
|
l********t 发帖数: 878 | 37 1. Know API, never heard ABI
2. All stacks pop
3. Hand all the way to the top, i.e. main(), and then halted by operating
system
4. Question not clear. Nothing, or constant class members.
5. reference is alias, bound forever, can not change.
pointer is more universal, unless you define something like
int * const *
Also there's some difference when you use reference/pointer as parameters
passed into a function.
6. C: printf printf printf printf printf
C++: cout cout cerr cerr
BTW: what do you mean... 阅读全帖 |
|
l**********7 发帖数: 55 | 38 来自主题: JobHunting版 - 请教一道题 牛!
Follow your idea. Here are my two cents.
void sortbst(int *A, int n)
{
int k, h;
//compute height
for (h=1;;h++) {
if (1<
}
//start the last left node with two leaves
//do inorder traverse the array
k=1<<(h-2)-1;
while(1)
{
printf(" %d ",A[2*k+1]);
printf(" %d ",A[k]);
printf(" %d ",A[2*k+2]);
if(2*k+2>=n-1) break;
printf(" %d ", A[k/2]);
k=k+1;
}
printf("n");
}
// a should be from a com... 阅读全帖 |
|
H**********5 发帖数: 2012 | 39 #include
#include
typedef struct node
{
int data;
struct node* next;
};
void printfList(struct node *head)
{
while(head!=NULL)
{
printf("%d-> ",head->data);
head=head->next;
}
printf("\n");
}
void pushAtBegin(struct node **head_ref,int data)
{
struct node *new_node=(struct node*)malloc(sizeof(struct node));
new_node->data=data;
new_node->next=*head_ref;
*head_ref=new_node;
}
void pushAtEnd(struct node **head_ref,i... 阅读全帖 |
|
h*****i 发帖数: 1017 | 40 #include
#include
using namespace std;
class binaryTree {
public:
int value;
int indx;
binaryTree *left;
binaryTree *right;
binaryTree(){
left = NULL;
right = NULL;
}
};
void insert(binaryTree *bTree, int num, int key){
if(bTree == NULL){
bTree = new binaryTree;
bTree->value = num;
bTree->indx = key;
printf("%d %dn",bTree->value,bTree->indx);
return;
... 阅读全帖 |
|
s***e 发帖数: 122 | 41 public static byte revByte(byte b) {
int ib = (b >= 0) ? b : b+256;
int ic = 0;
for (int i = 0; i < 8; ++i) {
ic = (ic*2) + (ib%2);
//System.out.printf("%d", ib%2);
ib /= 2;
}
//System.out.printf(" = %d\n", (byte)ic);
return (byte)ic;
}
or use bit operators:
public static byte revByte(byte b) {
int ib = b;
int ic = ib & 1;
//System.out.printf("%d", ib & 1);
for (int i = 1; i < 8; ++i) {
ib >>>= 1;
ic = (ic << 1) | (ib & 1);
//System.out.printf("%d", ib & 1);
}
//System.out.printf(" = %d\n", (byt |
|
c******t 发帖数: 133 | 42 刚接触c++ multithreading,自己用一个小例子想看看多线程能增加多少速度,由于电
脑是双核的,就想用两个threads把一个int array前后两部分分别排序,但不知道为什
么这个程序跟单线程排完前一半再排后一半的效率差不多,有没有同学指教一下,谢谢
了,代码如下。
#include
#include
#include
#include
using namespace std;
const int SIZE = 20000;
const int NO_OF_THREADS = 2;
void bubbleSort(int A[], int size, int);
void singleThread(int A[], int size)
{
clock_t t1, t2;
t1 = clock();
for(int i = 0; i < NO_OF_THREADS; i++)
bubbleSort(A+i*(SIZE/NO_OF_THREADS), SIZE/NO_... 阅读全帖 |
|
h******m 发帖数: 10 | 43 I got 2 cod of parent.c and child.c here:
parent.c:
#include
#define NULL 0
int main(void)
{
if(fork()==0){execve("child",NULL,NULL);exit(0);}
printf("Process[%d]:Parent in execution\n",getpid());
sleep(2);
if(wait(NULL)>0)printf("Process[%d]:Parent detects terminatin
child",getpid());
printf("Process[%d]:Parent terminating\n",getpid());
}
child.c:
int main()
{
printf("Process[%d]:child in execution\n",getid());
sleep(1);
printf("Process[%d]:child terminating\n",getid());
}
and |
|
i****x 发帖数: 17565 | 44 坑王必胜.c
#include
Printf("有没有教授敢亮工资?\n")
if(没人亮工资) printf("教授都是废物,没一个敢露面的,只有一群借四大牛人捧臭
脚,我呸!");
else {
if(工资低于码农) printf("教授都是穷酸蛋,读了半天书连小本工资都比不过,果然
是无能的臭老九!\n");
else printf("教授都是一群花和尚,本应该比学问,谈科研,却大言不惭在这里比工
资,谈福利,让人不齿!\n");
}
Return ("you win");
百战百胜,就是这么简单:)
★ Sent from iPhone App: iReader Mitbbs Lite 7.56 |
|
a**********s 发帖数: 588 | 45 I wrote a short program for OP to understand:
char buffer[65];
unsigned int N = 0x8fde27e3;
unsigned int A = 3, B = 17, K = 0x7893;
printf("N = %s....\n", itoa(N, buffer, 2));
printf("K = ..............%s ....\n", itoa(K, buffer, 2));
unsigned int Rk = (K << A);
unsigned int Ra = ((unsigned(-1) >> (32-A)) & N);
unsigned int Rb = ((-1 << (B+1)) & N);
unsigned int R = Ra | Rk | Rb;
printf("Ra = %s....\n", itoa(Ra, buffer, 2));
printf("Rk = %s....\n", |
|
c*********t 发帖数: 2921 | 46 写了一个很简单的程序,在linux下试了试,是segmentation fault, 程序退出。并且用
valgrind verify了一下,是同样的结果。
#include
// del_stack_variable.c
// this program tries to delete a variable in a function
//
int main()
{
int j=10;
printf("the addr of j =%p, j = %d\n", &j, j);
printf("delete j \n");
free(&j); //this will cause segmentation fault
printf("after that\n");
printf("the addr of j =%p, j = %d\n", &j, j);
return 0;
}
gcc -o del_stack del_stack_variable.c
$ ./del_stack
the addr of ... 阅读全帖 |
|
p*********b 发帖数: 47 | 47 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 ... 阅读全帖 |
|
s******e 发帖数: 108 | 48 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);
... 阅读全帖 |
|
s******n 发帖数: 3946 | 49 用一个List存放当前Open的XML tag。
每来一个数组,假设0~i匹配List的0~i,首先要关闭List里面i后面的所有tag,然后再
Push新来数组的i后面的所有Tag到List后面
所有数组跑完后再关闭List上所有的Tag
List temp;
String [][]input;
for (int i=0; i
String[] sentence = input[i];
int cursor;
for (cursor=0; cursor
+) {
if (!sentence[cursor].equals(temp[cursor]) break;
}
int closeTags = 0;
for (int j=temp.length()-1; j>=cursor; --j) {
printf("");
... 阅读全帖 |
|
k***t 发帖数: 276 | 50 看到一个 Space O(1)的,写了一下。
不过"(ab(xy)u)2)" -> "(ab(xyu)2)"而不是(ab(xy)u)2)" -> "(ab(xy)u)2"。
#define INVD -1
void balance (char *a) {
if (!a || !*a) return;
int l=0, u=(int)strlen(a)-1;
while (1) {
while (l<=u && a[l]!='(') {
if (a[l]==')') a[l]=INVD;
l++;
}
if (l>u) break;
while (u>=l && a[u]!=')') {
if (a[u]=='(') a[u]=INVD;
u--;
}
if (l>u) break;
l++; u--;
}
char *p=a;
bool dirty=false;
while (*a) {
... 阅读全帖 |
|