由买买提看人间百态

topics

全部话题 - 话题: argc
1 2 3 4 5 6 7 下页 末页 (共7页)
d**e
发帖数: 6098
1
来自主题: Programming版 - C的argc问题
【 以下文字转载自 JobHunting 讨论区 】
发信人: done (not done yet), 信区: JobHunting
标 题: C的argc问题
发信站: BBS 未名空间站 (Sat Oct 2 22:21:08 2010, 美东)
我用的是ubuntu, gcc 4.2.4
------------------------
#include
int main(int argc, char * argv[])
{
printf("argc = %d\n", argc);
return 0;
}
------------------------
比如我传入一个参数,输出是 2,正确
但如果我传入的是"*"符号,结果是 13 ... 这是为什么呢?
似乎只要有"*",argc至少就是13了。
谢谢
$ ./test 12 * 3
argc = 15
$ ./test *
argc = 13
$./test 12
argc = 2
d**e
发帖数: 6098
2
来自主题: JobHunting版 - C的argc问题
我用的是ubuntu, gcc 4.2.4
------------------------
#include
int main(int argc, char * argv[])
{
printf("argc = %d\n", argc);
return 0;
}
------------------------
比如我传入一个参数,输出是 2,正确
但如果我传入的是"*"符号,结果是 13 ... 这是为什么呢?
似乎只要有"*",argc至少就是13了。
谢谢
$ ./test 12 * 3
argc = 15
$ ./test *
argc = 13
$./test 12
argc = 2
r****o
发帖数: 1950
3
来自主题: JobHunting版 - C的argc问题
I tested in VC, input "test *"
output "argc=2"
w*****x
发帖数: 116
4
来自主题: Programming版 - 问一下关于if(argc!=2)的代码的问题
初学RB tree ,看到一段C++代码是:
if(argc!=2){
cout<<"Usage: The numbers of tree nodes"< return -1;
}
else{。。。。}
对这段不熟悉, 为什么要设置这个 控制?看书叫外部命令行,但是在这里对树的节点
没有关系。这个设置有必要吗?
不要见笑。谢谢。
g****g
发帖数: 1828
5
来自主题: Linux版 - awk
AWK是一种优良的文本处理工具,Linux及Unix环境中现有的功能最强大的数据处理引擎
之一。这种编程及数据操作语言(其名称得自于它的创始人 阿尔佛雷德·艾侯 、
Peter Weinberger 和 Brian Kernighan 姓氏的首个字母)的最大功能取决于一个人所
拥有的知识。 AWK 提供了极其强大的功能:可以进行正则表达式的匹配,样式装入、
流控制、数学运算符、进程控制语句甚至于内置的变量和函数。它具备了一个完整的语
言所应具有的几乎所有精美特性。实际上 AWK 的确拥有自己的语言: AWK 程序设计语
言, 三位创建者已将它正式定义为“样式扫描和处理语言”。它允许您创建简短的程
序,这些程序读取输入文件、为数据排序、处理数据、对输入执行计算以及生成报表,
还有无数其他的功能。gawk 是 AWK 的 GNU 版本。
最简单地说,AWK 是一种用于处理文本的编程语言工具。AWK 在很多方面类似于 Unix
shell 编程语言,尽管 AWK 具有完全属于其本身的语法。它的设计思想来源于
SNOBOL4 、sed 、Marc Rochkind设计的有效性语言、语言工具 y... 阅读全帖
d**********o
发帖数: 1321
6
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
hw3b c-.y file
上面这一楼贴了载止hw3b deadline时我match的结果(也就是老师可以以这些不match
的ERROR为借口不给后来我补上的成绩),但是因为当时我还是没有写完,后来感恩节
期间就接着又写了一些,而且hw5是based on hw3 & hw3b的基础上(当我hw5是based
on更好的hw3的结果时,我应该可以得更多的分吧)。
hw4因为写得比较顺利,就不曾保留任何交上去作业的output,没有什么一目了然的结
果是我可以贴在这里的。原本我是想要把自己最的一次作业hw5贴出来的,但那已经是
一个完整的compiler,而且以后我还需要用自己的course project来找工作,所以一定
就不贴最终结果了。那就贴一个hw3b的c-.y文件吧,它集中的hw1、hw2、hw3、 hw3b的
结果,是我自己hw3b *.y文件的最完整版本。这些作业里面也有很多机关一一人为增加
的难度,比如那六七个IO相关的function,不仅traverse tree、build syntax tree的
时候会成为一个考点(把它们作为一个node连在syntax... 阅读全帖
d**********o
发帖数: 1321
7
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
hw3b c-.y file
上面这一楼贴了载止hw3b deadline时我match的结果(也就是老师可以以这些不match
的ERROR为借口不给后来我补上的成绩),但是因为当时我还是没有写完,后来感恩节
期间就接着又写了一些,而且hw5是based on hw3 & hw3b的基础上(当我hw5是based
on更好的hw3的结果时,我应该可以得更多的分吧)。
hw4因为写得比较顺利,就不曾保留任何交上去作业的output,没有什么一目了然的结
果是我可以贴在这里的。原本我是想要把自己最的一次作业hw5贴出来的,但那已经是
一个完整的compiler,而且以后我还需要用自己的course project来找工作,所以一定
就不贴最终结果了。那就贴一个hw3b的c-.y文件吧,它集中的hw1、hw2、hw3、 hw3b的
结果,是我自己hw3b *.y文件的最完整版本。这些作业里面也有很多机关一一人为增加
的难度,比如那六七个IO相关的function,不仅traverse tree、build syntax tree的
时候会成为一个考点(把它们作为一个node连在syntax... 阅读全帖
O***e
发帖数: 89
8
来自主题: Programming版 - A aimple C++ question
I know the meaning of argc and argv, but why argc=3 is required in many
programs, the following is an example.
#int main(int argc, char * argv[])
#{
#char chline[LINESIZE+1];
#const char * self=argv[0];
#const char * ipfile=argv[1];
#const char * opfile=argv[2];
#if ( ! (argc==3))
#{
#if (argc<3)
#cout<<"\n\nerror: too few arguments"< #if (argc>3)
#cout<<"\n\nerror: too many parameters"<
e********r
发帖数: 2352
9
来自主题: JobHunting版 - Epic Written Interview
在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
时,快累死了。
数学题基本上就是脑筋急转弯,举几个例子
1. You have three kinds of magazines, all but two are Times, all but two are
Science, all but two are Nature. How many magazines in total do you have?
3 books
2. Only one of the answers is true
A. All of the below are true
B. All answers are true
C. One of the above is true
D. All of the above are true
E. None of the above ar... 阅读全帖
l*****8
发帖数: 16949
10
下面这个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
11
来自主题: Joke版 - Evolution of a programmer
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");
}
... 阅读全帖
EM
发帖数: 715
12
来自主题: Programming版 - [C++ boost::interprocess] 讨论贴
在parent process里面建立一个{1,2,3}的set,然后在child process里面打印出来,编
译可以通过,但是为什么会有segmentation fault呢?读了大半天boost的东东也没搞
明白,请大侠指导一下
程序如下,编译如右:g++ -std=c++0x src.cc -lrt
#include
#include
#include
#include //std::system
#include
#include
#include
using namespace boost::interprocess;
//Main function. For parent process argc == 1, for child process argc == 2
int main(int argc, char **argv)
{
if(argc == 1... 阅读全帖
c********s
发帖数: 817
13
This is my implementation for these two functions, and a driver to run them.
cat string_reverse.c
#include
#include
#include
void swap(char* c1, char* c2);
// -----------------
void string_reverse1(char* string) {
if (string == NULL)
return;
char* head = string;
char* tail = head;
// find the tail
while (*tail) ++tail;
--tail;
// while loop to do the swap
while (head < tail)
swap(head++, tail--);
}
// -----------------
// the caller of this function is res... 阅读全帖
E*****7
发帖数: 128
14
来自主题: Programming版 - A aimple C++ question
#if ( ! (argc==3))
这是测试在命令行执行该文件时,文件名的后面是不是带有两个参数:
C:\ExeThisCode para_1 para_2
后面:
#if (argc<3)
#cout<<"\n\nerror: too few arguments"< #if (argc>3)
#cout<<"\n\nerror: too many parameters"< 程序员要求在命令行执行该文件时文件名的后面必须带有两个参数,否则给出错信
息(参数太少,参数太多)。
X****r
发帖数: 3557
15
来自主题: Programming版 - tree data conversion
右边第一行应该是1->2,不是1->1吧。
我不懂perl,不过这个程序实在简单,用C写一个也就几行:
int expand(int input[], int output[][2], int start) {
int branch, end = start + 1;
for (branch = 0; branch < input[start]; ++branch) {
output[start][branch] = end;
end = expand(input, output, end);
}
return end;
}
验证程序:
#include
#include
#define MAX 100
int main(int argc, char *argv[]) {
int input[MAX], output[MAX][2] = {0};
int i;
for (i = 1; i < argc; ++i) {
input[i] = atoi(argv[i]);
}
printf... 阅读全帖
g****y
发帖数: 436
16
来自主题: Programming版 - const 指针类型转换
搞不明白怎么回事。。。
指针不能自动做const 转换吗?
// file_func.cpp
namespace const_test{
void const_para(const int para) {}
void const_para(const int para, const char** pppara ) {}
}
int main(int argc, char** argv){

const int c_argc = argc; //ok. does not harm
const_test::const_para(c_argc);//ok. type match
const_test::const_para(1); //ok. type match
const_test::const_para(argc); //ok. auto type conversion.

const_test::const_para(para, argv); //error. Can not convert from
... 阅读全帖
l******o
发帖数: 67
17
写了个word search 的程序。 在 windows上 run的结果是对的,但是把程序和文件 放
到 linux上run的时候结果总是不对。 以为是 line ending 的问题,改了下程序还是
不行。 请教下版内大牛帮着看下, 到底是哪里出问题了。 不胜感激
下面是主函数。word_search(honey_comb,s.c_str()) 这个函数,我感觉写的没问题,
因为在windows上run的结果完全没问题
int main(int argc, char *argv[]){
/////////////////////////////////////////////////////////////////////
// read file
ifstream honey_if;
ifstream dict_if;
string honey_path;
string dict_path;

if(argc>=2){
honey_path=argv[1];
}else{
honey_pa... 阅读全帖
a**u
发帖数: 59
18
来自主题: RisingChina版 - our vote code
// 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
M**Y
发帖数: 431
19
来自主题: JobHunting版 - 几道面试小题
1. With these variable declarations: int i, j[10], *k;
Which of the following are legal?
a. i = *(&(j[2]) + 1);
b. k = &(j[1]);
c. i = &(j[2]) + 1;
2. Assuming the function lookupName is defined, what's wrong with this code
(hint: 2 bugs)?
const char *getName(const char *c) {
std::string name = lookupName(c);
if (name == NULL)
return "Anonymous";
return name.c_str();
}
int main(int argc, char *argv[]) {
const char *name = NULL, *c = NULL;
if (argc >= 2)
c = ar
w********p
发帖数: 948
20
来自主题: JobHunting版 - 讨论个subarray sum的变种问题
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
m******e
发帖数: 353
21
来自主题: JobHunting版 - one amazon interview problem
#include
#include
void countOnesAndZeros(int &numZeros, int &numOnes, const std::vector &
sequence) {
numOnes = 0;
numZeros = 0;
for(size_t i = 0; i sequence[i] == 1 ? ++ numOnes : ++ numZeros;
}
}
int trimLeft(const std::vector &sequence, int start, int numToTrim, int
untilSeenSymbol) {
int trimCnt = 0;
while(start + trimCnt >= 0 && start + trimCnt < (int) sequence.size() &&
numToTrim > 0) {
if(sequenc... 阅读全帖
l*******o
发帖数: 791
22
来自主题: JobHunting版 - c++ 程序一问
楼上说的对。
问题出现在你的test函数,test函数接受的是一个以值传递的指针。比如说一个经典的
swap(int a, int b)的例子,必须写成swap(int * a, int * b)或者引用才能改变外
界传入函数参数的值。同理如果你想改变一个指针的值,你需要用对一个指向这个指针
的指针进行操作,
所以test必须写成
void test (char * * p)
{
*p = new char[10];
memset((*p), 'A', 10);
}
然后main函数写成
int main(int argc, char *argv[])
{
char *k;

test(&k);
cout << k << endl;
}
不过一般倾向于使用引用即reference这样你就不会混淆,reference版本如下
void test( char * & p )
{
p = new char[10];
memset(p, 'A', 10);
int main(int argc, char *argv[])
{... 阅读全帖
c***2
发帖数: 838
23
来自主题: JobHunting版 - map numbers to strings
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... 阅读全帖
b*****e
发帖数: 474
24
很不错了。细节可以再推敲一下,算法本身(基于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 ... 阅读全帖
g*******s
发帖数: 490
25
感想,居然第一题就考到了goto。。我靠。。
有两三道题程序实在是太长,一堆指针+loop,看不清楚,不过这些程序基本是找错。。只能看答案猜了
最好两台电脑,一台要打程序,查资料操作不过来,如果有帮手就更好了
1. variable definition 和 declaration的 区别
2. 怎么是最portable的方法操作integer最高位的那个byte,比如设1
3. vfprintf考到了
4. char *x;
x="abcd"
请问这个操作的意义,合法不合法?空间是怎么allocate
5. freebsd某个头文件的一个macro
#if defined xxxx
#define _p(xxx) (xxx)
#else
#define _p(xxx) ()
#end
what does this macro for
6. memcpy 在某个iso xxx标准中的标准declaration是
7. memmve
8.哪个方法是一个c program必须的方法,main?
9. c提供了哪个方法获取 any file的 size
10. file * fp ... 阅读全帖
j***y
发帖数: 2074
26
来自主题: JobHunting版 - 这题哪错了?

如果能写成这样,那么就可以写成int fun(int **p)了。
记得int main(int argc, char *argv[])也可以写成int main(int argc, char **argv)
Chevy提供的是正确的用法。
相似的例子在K&R的书上也有:
If a two-dimensional array is to be passed to a function, the parameter
declaration in the function must include the number of columns; the number
of rows is irrelevant, since what is passed is, as before, a pointer to an
array of rows, where each row is an array of 13 ints. In this particular
case, it is a pointer to objects that are arrays of 13 ints. Thus i... 阅读全帖
l**********3
发帖数: 161
27
来自主题: JobHunting版 - 求顺时针打印矩阵code
贴个简单点的,但是比较长 。。。
==============
#include
#include
#include
#include
using namespace std;
enum direct_t { RIGHT, DOWN, LEFT, UP };
void print_spiral_matrix(int dimX, int dimY)
{
int** matrix = new int*[dimX];
for (int i=0; i {
matrix[i] = new int[dimY];
memset(matrix[i], 0, sizeof(int)*dimY);
}

int num = 1;
direct_t dir = RIGHT;
int i, j;

for (i=j=0; num <= dimX*dimY; ++num)
{
ma... 阅读全帖
f*******t
发帖数: 7549
28
来自主题: JobHunting版 - large file的一道题
这个是很基本的数据结构,建议看一下wiki
我前几天实现了它,只有基本的insert和search,没有对查找child list进行优化,代
码贴出来供参考:
#include
#define MAX_LENGTH 64
using namespace std;
static char buff[MAX_LENGTH];
class Trie {
public:
Trie();
Trie(char value);
bool Insert(const char *str);
bool Search(const char *str) const;
void PrintAll(int pos) const;
private:
char _value;
Trie *_sibling;
Trie *_child;
};
Trie::Trie()
{
_value = 0;
_sibling = NULL;
_child = NULL;
}
Trie::Trie(char value)
... 阅读全帖
m******e
发帖数: 353
29
来自主题: JobHunting版 - 从水木上看到个数组题
ok, my bad, keep track of range [0, neg) and [numNeg, pos), and do not
rearrange those (since they are already in the correct place)
use [neg, numNeg) and [pos, N) as circular buffer for un-processed elements
#include
#include
#include
using namespace std;
void print(const vector& input) {
for(size_t i = 0; i < input.size(); ++i) {
cout << input[i] << " ";
}
cout << endl;
}
int numNegatives(const vector& input) {
int cnt = 0;
... 阅读全帖
p*i
发帖数: 411
30
来自主题: JobHunting版 - 问一道kth smallest element的题目
#include
#include
#include
#include
using namespace std;
inline void swap(int &a, int &b) {
int t = a; a = b; b = t;
}
int partition(vector& work, vector& indices, int p, int q) {
// use work[q] to partition the array
const int x = work[q];
int i = p-1;
for (int j = p; j < q; j++) {
if (work[j] < x) {
i++;
swap(work[i], work[j]);
swap(indices[i], indices[j]);
}
}
i++;... 阅读全帖
p*i
发帖数: 411
31
来自主题: JobHunting版 - 上一道题吧
#include
#include
#include
using namespace std;
void process(const string& str) {
stack s, s1;
for (unsigned i = 0; i < str.size(); i++) {
if ('(' == str[i]) {
s.push(i);
} else {
if (!s.empty()) {
unsigned left = s.top(); s.pop();
unsigned& right = i;
if (s1.empty() || (s1.top()+1 < left)) {
s1.push(left);
s1.push(right);
... 阅读全帖
C***U
发帖数: 2406
32
#include
#include
#include
#define MAX 10000
int main(int argc, char *argv[]){
std::vector numbers1;
std::vector numbers2;
int k = atoi(argv[3]);
if(argc < 4)
std::cout << "we need 2 files and a number." << std::endl;
std::cout << "we need find " << k << "th number" << std::endl;
std::cout << "reading first array of numbers ..." << std::endl;
std::ifstream f1(argv[1]);
if(!f1){
std::cout << "cannot open... 阅读全帖
j********e
发帖数: 1192
33
来自主题: JobHunting版 - 插入节点到complete binary tree的末尾
写了个使用O(1)memory, O(logN * logN) (N是tree的size)的程序。
类似于binary search的算法,测试代码也在下面,应该没有大bug。
先获得树的高度h,然后比较h和root->right子树的高度+1,如果相同,
说明树最后一个节点在root->right,否则最后一个节点在root->left的子树。
#include
#include
#include
#include
using namespace std;
class Node {
private:
Node *left;
Node *right;
int value;

public:
Node() {
left = right = NULL;
value = 0;
}

Node(int v) {
left = right = NULL;
value = v;
}

int Height(Node *node) {
int h... 阅读全帖
g**********t
发帖数: 475
34
Isn't it very slow to swap one array k times? Remember that k could be very
large! I attached my code using a different idea.Its complexity is O(n^2).
#include
#include
#include
#include
using namespace std;
int permutation(int n){
int p = 1;
for(int i = 1; i <= n; i ++){
p *= i;
}
return p;
}
string perSeq(int n, int k){
string output;
bool flag[10];
fill_n(flag, 10, false);
--k;
for (int i = 1; ... 阅读全帖
j*****y
发帖数: 1071
35
来自主题: JobHunting版 - F面经
写了一个,欢迎测试
#include
#include
#include
#include
#include
using namespace std;
bool isNumber(string s)
{
if(s[0] == '+' || s[0] == '-' || s[0] == '(' || s[0] == ')')
{
return false;
}
return true;
}
int helper(int a, int b, char c)
{
if(c == '+')
{
return a + b;
}
else
{
return a - b;
}
}
bool valid(vector &s)
{
stack v;
stack c;
for(int i = 0; i < s.size(); ++i)
... 阅读全帖
d****n
发帖数: 1241
36
来自主题: JobHunting版 - F面经
可以使用编译器在lexing和parsing的时候用的某种技术:recursive descent parsing
http://en.wikipedia.org/wiki/Recursive_descent_parser
下边的代码假设单个的数字也是合法的,比如:
1 合法
(1)合法
(1) + (2) 合法, 等等
#include
#include
#include
#include
using namespace std;
enum TokenKind {
TOK_Unknown = -1,
TOK_End,
TOK_Op,
TOK_LParen,
TOK_RParen,
TOK_Num,
};
static TokenKind getToken(const string &Input, int &Pos)
{
assert(Pos <= Input.length());
char TheChar = Input[Pos];
while (isspace(TheC... 阅读全帖
j*****y
发帖数: 1071
37
来自主题: JobHunting版 - F面经
写了一个,欢迎测试
#include
#include
#include
#include
#include
using namespace std;
bool isNumber(string s)
{
if(s[0] == '+' || s[0] == '-' || s[0] == '(' || s[0] == ')')
{
return false;
}
return true;
}
int helper(int a, int b, char c)
{
if(c == '+')
{
return a + b;
}
else
{
return a - b;
}
}
bool valid(vector &s)
{
stack v;
stack c;
for(int i = 0; i < s.size(); ++i)
... 阅读全帖
d****n
发帖数: 1241
38
来自主题: JobHunting版 - F面经
可以使用编译器在lexing和parsing的时候用的某种技术:recursive descent parsing
http://en.wikipedia.org/wiki/Recursive_descent_parser
下边的代码假设单个的数字也是合法的,比如:
1 合法
(1)合法
(1) + (2) 合法, 等等
#include
#include
#include
#include
using namespace std;
enum TokenKind {
TOK_Unknown = -1,
TOK_End,
TOK_Op,
TOK_LParen,
TOK_RParen,
TOK_Num,
};
static TokenKind getToken(const string &Input, int &Pos)
{
assert(Pos <= Input.length());
char TheChar = Input[Pos];
while (isspace(TheC... 阅读全帖
s*w
发帖数: 729
39
来自主题: JobHunting版 - 背包问题
codeeval.com 上的一个题
给n个东西,每个东西有重量和价值,要求在重量小于给定值的时候,尽量价值大
在重量是浮点数的情况下,怎么做 bottomup 的 dp table?
我现在的解是 recursion, 而且没 memorization, 因为不知道怎么存这个 table.
帖下代码,请指教一下
#include
#include
#include
#include
#include
#include
using namespace std;
class Solution {
int weightLimit;
int n;
vector weights;
vector costs;
public:
Solution(const string &line) {
istringstream iss(line);
iss >> weightLimit;
int in... 阅读全帖
xt
发帖数: 17532
40
我搞到了一个小程序:
#include
#include
#include
#include
#include
int main( int argc, char** argv)
{
char buf[80] = {0};
int myfile;
pid_t pid;
struct psinfo psi;
if ( argc<2 ){
printf("Usage: %s PID\n", argv[0]);
return 1;
}
pid=atoi(argv[1]);
sprintf( buf, "/proc/%d/psinfo", pid);
myfile = open( buf, O_RDONLY );
if (myfile < 0)
perror( "open" );
if ( read( myfile, & psi, sizeof(psi) ) < 0 )
perror( "read" );
close( myfile );
printf( "%s
T****e
发帖数: 2167
41
来自主题: Cantonese版 - [合集] 问问在德州呆过嘎前辈~
☆─────────────────────────────────────☆
greg (int argc, char *argv[]) 于 (Wed Oct 11 20:07:15 2006) 提到:
ece 类MS grad 的第一份工作salary大嘎会在什么范围?
准备要去austin/tx on-site~
☆─────────────────────────────────────☆
ooev (72) 于 (Wed Oct 11 20:07:50 2006) 提到:
salary.com参考一下?

☆─────────────────────────────────────☆
greg (int argc, char *argv[]) 于 (Thu Oct 12 09:57:03 2006) 提到:
what I should answer if i am asked what's my expected salary ??
☆─────────────────────────────────────☆
ooev (72) 于 (
a*****n
发帖数: 14370
42
来自主题: Cantonese版 - [合集] 万圣节又到啦!!!
☆─────────────────────────────────────☆
Cajal (chump) 于 (Sun Oct 29 00:04:42 2006) 提到:
今晚刻了三个小时的南瓜:
☆─────────────────────────────────────☆
Cajal (chump) 于 (Sun Oct 29 00:08:55 2006) 提到:
呵呵

☆─────────────────────────────────────☆
aladdin (渔夫) 于 (Sun Oct 29 00:23:54 2006) 提到:
很好很好,我也嗑了一个:
☆─────────────────────────────────────☆
Cajal (chump) 于 (Sun Oct 29 00:32:05 2006) 提到:
我曾经搜索到一个网站,专门设计各种很e的南瓜刻法的,里面也包括了你这种的。:D
☆─────────────────────────────────────☆
Toffee (Gals On Dema... 阅读全帖
h**c
发帖数: 2376
43
刚刚follow了一下xcode里的helloview,搞半天也没有搞懂
main.m 是怎么去找HelloView.h什么的
就这几行代码,它怎么就知道要去找HelloView呢?
#import
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
还请各位大侠指教
h**c
发帖数: 2376
44
【 以下文字转载自 Apple 讨论区 】
发信人: hocc (wency denise ho), 信区: Apple
标 题: 问个剧土的关于Xcode的helloworld问题
发信站: BBS 未名空间站 (Mon Feb 14 22:34:59 2011, 美东)
刚刚follow了一下xcode里的helloview,搞半天也没有搞懂
main.m 是怎么去找HelloView.h什么的
就这几行代码,它怎么就知道要去找HelloView呢?
#import
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
还请各位大侠指教
E*V
发帖数: 17544
45
来自主题: Linux版 - 这本书比较好玩
程序员进化史
初中/高中
10 PRINT "HELLO WORLD"
20 END
大学一年级
program Hello(input, output);
begin
writeln('Hello world');
end.
大学四年级
(defun hello ()
(print (list 'HELLO 'WORLD)))
刚参加工作
#include
main (argc, argv)
int argc;
char **argv; {
printf ("Hello World!\n");
}
老手
#include
const int MAXLEN = 80;
class outstring;
class outstring {
private:
int size;
char str[MAXLEN];
public:
outstring() { size=0; }
~outstring() { size=0; }
void print();
void assign(char *chrs);
};
void outstring::prin
w*s
发帖数: 7227
46
【 以下文字转载自 Programming 讨论区 】
发信人: wds (净洗前尘,从头再来), 信区: Programming
标 题: segmentation fault as soon as entering 1 function in the arm processor board
发信站: BBS 未名空间站 (Sat Dec 15 22:20:01 2012, 美东)
Hi everyone,
i'm lost on this one, can someone give me some hints ?
1. downloaded latest stunnel package from web
2. build in the host linux and runs fine
3. build for arm target (am using the same settings from before,
my task is to upgrade to latest stunnel)
4. builds ok, when run in arm board, seg fau... 阅读全帖
f********f
发帖数: 8
47
来自主题: Programming版 - 关于C C++ 和java的文件读写问题
要求:a file is to be copied and at the same time its content has to be
reversed (byte by byte)
程序的问题是,当文件很大时, 出错.
请各位大虾,还有聪明的小米,还有好心的xdjms,多多指点. :-)
c语言
#include
#include
#define BUFFER_SIZE 1
int main(int argc, char *argv[])
{
FILE *fp_src, *fp_dest;
void *buffer;
int read;
unsigned int fpSize = 0;
int i,j;
buffer = malloc(BUFFER_SIZE);
if (argc != 3)
{
printf("usage: rcopy srcFile destFile \n");
n*c
发帖数: 228
48
来自主题: Programming版 - a question on C++ string
#include
#include
int main(int argc,char* argv[])
{
std::string s;
for(int i=1;i<=argc;i++)
s+=argv[i];
std::cout< return 0;
}
This one gave me "segmentation fault".
I suppose this is because s is empty
I tried ./prog i love china
Can someone explain?
s*****d
发帖数: 43
49
来自主题: Programming版 - a question on C++ string
i<=argc
should be
i < argc
I**********s
发帖数: 441
50
来自主题: Programming版 - python的一大缺点
My filter used to change tab to space:
/*
* @usage: ./filter [n]
* The optional n is the number of spaces to replace a tab.
* n default to 4.
*/
void main(int argc, char ** argv) {
char c;
int i, n = (argc > 1) ? atoi(argv[1]) : 4;
while ((c = getchar()) != EOF) {
if (c == '\t') { for (i = 0; i < n; i ++) putchar(' '); }
else { putchar(c); }
}
}
1 2 3 4 5 6 7 下页 末页 (共7页)