由买买提看人间百态

topics

全部话题 - 话题: char
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
S******1
发帖数: 216
1
//11:55 第3题不是图,是disjoint set
boolean isRight(String[] ss1, String[] ss2) {
if (ss1 == null || ss2 == null)
return false;

Map indexMap = new HashMap();
for (String s : ss1) {
char c1 = s.charAt(0);
char c2 = s.charAt(2);
if (!indexMap.containsKey(c1))
indexMap.put(c1, indexMap.size());
if (!indexMap.containsKey(c2))
indexMap.put(c2, indexMap.size());
}

int[] set = ne... 阅读全帖
H**********5
发帖数: 2012
2
来自主题: JobHunting版 - 请帮忙看段code,为什么过不了。
你的代码本身没问题,
我怀疑是你写测试时

char a[]=“12345”;
写成
char a*=“12345”;
导致常量字符被修改程序死掉的错误。
我刚才在VC6跑了你的代码没有问题
#include
#include
void reverse(char* str)
{
// check null
if ( str == NULL ) return;
char* end = str;
char temp;
while( *end != NULL )
end++;
end--;
while( str < end )
{
temp = *str;
*str = *end;// 这里每次都会垮掉
*end = temp;
str++;
end--;
}
}
main()
{
char a[]="12345";
reverse(a);
cout< }
a***e
发帖数: 413
3
来自主题: JobHunting版 - Implement strStr() ?
找到一个解释比wiki清楚的source
http://www.inf.fh-flensburg.de/lang/algorithmen/pattern/kmpen.h
下面是根据那个原理写的KMP,这下觉得清楚多了。和正在学习的同学共享一下。。。
。。。顺便多谢各位。。。。
class Solution {
public:
char *strStr(char *haystack, char *needle) {
int pos = kmpSearch(haystack, needle);
if (pos == -1) return nullptr;
else return haystack + pos;
}
static void kmpPreprocess(const char *p, vector &b)
{
int i = 0, j = -1;
b[i] = j;
const int m = strlen(p);
... 阅读全帖
m**s
发帖数: 61
4
来自主题: JobHunting版 - Linkedin 电面 面经x2
char findNextChar(char[] list, int length, char target)
{
==>need error handling for list
[Agree]
// target is not within the list, just return the 1st char
if (target < list[0] || target > list[length - 1])
return list[0];
==> why return list[0] when target>
[题目要求的,for wrap case,return list中最小的character]
int left = 0, right = length - 1;
char result = list[0];
while (left < right) {
int mid = (left + right)/ 2;
==> overflow
[题目中说的是char array,不会overflow,不过我很喜欢... 阅读全帖
m**s
发帖数: 61
5
来自主题: JobHunting版 - Linkedin 电面 面经x2
char findNextChar(char[] list, int length, char target)
{
==>need error handling for list
[Agree]
// target is not within the list, just return the 1st char
if (target < list[0] || target > list[length - 1])
return list[0];
==> why return list[0] when target>
[题目要求的,for wrap case,return list中最小的character]
int left = 0, right = length - 1;
char result = list[0];
while (left < right) {
int mid = (left + right)/ 2;
==> overflow
[题目中说的是char array,不会overflow,不过我很喜欢... 阅读全帖
a***e
发帖数: 413
6
来自主题: JobHunting版 - 能不能讨论一下kmp
曾经问过,7月份的时候花了好多时间搞清楚,现在又忘了,就记得个大概。而且以前
看着很清楚的网页现在一看没有啦。。。。。。。觉得还是看图最清楚
http://www.mitbbs.com/article_t/JobHunting/32742535.html
找到一个解释比wiki清楚的source
http://www.inf.fh-flensburg.de/lang/algorithmen/pattern/kmpen.h
下面是根据那个原理写的KMP,这下觉得清楚多了。和正在学习的同学共享一下。。。
。。。顺便多谢各位。。。。
class Solution {
public:
char *strStr(char *haystack, char *needle) {
int pos = kmpSearch(haystack, needle);
if (pos == -1) return nullptr;
else return haystack + pos;
}
static void km... 阅读全帖
r**d
发帖数: 116
7
来自主题: JobHunting版 - 问一个有关c++ strcmp的问题
下面是apple的source code. 我不明白为什么需要把char 转换成unsigned char?
strcmp(const char *s1, const char *s2)
{
for ( ; *s1 == *s2; s1++, s2++)
if (*s1 == '\0')
return 0;
return ((*(unsigned char *)s1 < *(unsigned char *)s2) ? -1 : +1);
}
g****v
发帖数: 971
8
来自主题: JobHunting版 - 请教个LC的新题
Read N Characters Given Read4 II - Call multiple times
测试的输出是:
Input: "ab", [read(0),read(1),read(2),read(1)]
Output: ["","a","b","b"]
Expected: ["","a","b",""]
我的思路很简单,就是把上次没读完的保留下来(并且是把没读完的字符移动到index
0). 下次读的时候先读上次剩下的。但不知道为什么不对?
class Solution {
int left = 0; //length of left chars of last time reading, staring from
0 of leftover.
char leftover[4];//left chars are stored here.
public:
/**
* @param buf Destination buffer
* @param n Maximum number of characters t... 阅读全帖
t*****a
发帖数: 106
9
有限状态机不是早被批的体无完肤了吗...早没人用了。 贴个code,按别人的
思想写的
class Solution {
public:
int skipwhitespace(const char *p)
{
int i=0;
while(*(p+i)==' ') i++;
return i;
}
int skipsign(const char *p)
{
if(*p=='+'||*p=='-') return 1;
return 0;
}
int skipdigit(const char *p)
{
int i=0;
while(isdigit(*(p+i))) i++;
return i;
}
bool isNumber(const char *s) {
char *p=const_cast(s);
if(p==NULL) ret... 阅读全帖
s**********r
发帖数: 88
10
来自主题: JobHunting版 - 急问F家面试一题
面试题目是 Leetcode: One Edit Distance 变题:
bool isOneEditDistance(char *s, char *t){
// 具体要求:s 和 p 是字符流,所以不能使用strlen,预先得到 s 和 t 的长度

}
平时看到的解法都是需要先知道字符串的长度。回来我想了想,给了个解法,如下。但
这个解法,对下面的Test case 对不过。但实际上,p11 与 s11的 Edit distance 是
1。 请高人指点。
char * p11 = "ABBAAABBBBBBBBBBBBBBBBBBBBBBCBB";
char * s11 = "ABBAAABBBBBBBBBBBBBBBBBBBBBBBB";
bool isOneEditDistance(char *p, char *s){
// Corner case
if(*p=='
j**********3
发帖数: 3211
11
我的代码,Time Limit Exceeded.
自己拖下来放到eclipse里边,跑到死机了。。。到底哪里出错了?
public int numIslands(char[][] grid) {
if(grid == null){
return 0;
}
int m = grid.length;
if(m == 0){
return 0;
}
int n = grid[0].length;
char c = 'A';

for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if (grid[i][j] == '1') {
bfs(grid, i, j, c, m, n);
c = (char)(c + 1)... 阅读全帖
p****6
发帖数: 724
12
来自主题: JobHunting版 - 报几个offer

建一个hashmap,char map to a list 这个char出现过的index,
list是ordered,这个hashmap只存要找的那几个char,从第一个char开始找,pop掉
linkedlist的头如果这个index比之前char的index大。这样讲有点不清楚,你只要把
hashmap画出来我相信你一眼就看出来怎么做了。
y**********a
发帖数: 824
13
来自主题: JobHunting版 - Google 电面

public static String boardMove(String s, char c, int n) {
StringBuilder res = new StringBuilder();
for (int i = 0; i move(c, s.charAt(i), n, res);
c = s.charAt(i);
}
return res.toString();
}
static void move(char c1, char c2, int n, StringBuilder res) {
int a = c1-'a', b = c2-'a';
int x1 = a/n, x2 = b/n, y1 = a%n, y2 = b%n;
int dx = Math.abs(x1-x2), dy = Math.abs(y1-y2);
char v... 阅读全帖
I**********s
发帖数: 441
14
a+b应该不match b吧?
代码如下:
bool match(const char * s, const char * p) {
if (! *p) return ! *s;
if (*(p + 1) == '*') {
// match(s+1, p) - match next char in s.
// match(s, p+2) - match exactly nothing in s.
if (*p == *s) return match(s+1, p) || match(s, p+2);
else return match(s, p+2); // matche exactly nothing in s.
}
else if (*(p + 1) == '+') {
// match(s+1, p) - match next char in s.
// match... 阅读全帖
N***m
发帖数: 4460
15
来自主题: Java版 - 问个数组问题
来个效率比较低的,不知道有没有bug
public class Main {
public static void main(final String[] args) {
char[] source = { 'a', 'a', 'b', 'b', 'b', 'b', 'a', 'c', 'd', 'd', 'a
' };
new Main().removeDup(source);
for (char c : source) {
if (c != 0) {
System.out.print(c);
} else {
break;
}
}
System.out.println();
}
void removeDup(final char[] source) {
for (int i = 1; i < source.length; i++) {
if (this.contains(so... 阅读全帖
s*******d
发帖数: 59
16
来自主题: Programming版 - why int** cannot convert to const int** ?
int main() {
const char c = 'c';
char* pc;
const char** pcc = &pc; //1: not allowed
*pcc = &c;
*pc = 'C'; //2: modifies a const object
}
const char **
是说char 是const,还是说char* 是const?
n*******s
发帖数: 482
17
这个是书上的一个章节总结的题目,不会做。
C++ Strategies and Tactics 第二章的一个问题
9。假设我们正使用String类, 它提供了一个operator const char*的转换函数:
class String
{
public:
operator const char*() const;
}
另有一个remove_blanks函数
void remove_blanks(char* cp)
{
char* p = cp;
while(*p)
{
if(*p!= ' ' )
*cp++ = *p;
++p;
}
*cp = '\0'
}
如果有人这样用
String s(" hello world ");
remove_blanks((char*)(const char*)s);
这样用有什么问题呢?
/**
* 我觉得如果 调用的时候写成
* remove_blanks
o******r
发帖数: 259
18
那是你没写对吧,(char*)((const char*)s)
试试下面这个:
const char chT1[] = "Hello!";
const char* pch1 = chT1;
cout << pch1 < char* pch2 = (char*)chT1;
pch2[5] = '?';
cout << pch2 <
v*********o
发帖数: 5
19
来自主题: Programming版 - 问sscanf
在C程序的头文件中,假如有结构体定义如下:
typedef struct FrameworkComponent
{
char Name[256];
char NameIons[256];
} FRAMEWORK_COMPONENT;
extern FRAMEWORK_COMPONENT FrameworkComponent[2];
而在主函数中有:
char arguments[256];
sscanf(arguments,"%s",(char*)&FrameworkComponent[0].Name);
sscanf里面 (char*)&是什么意思?
Name作为字符数组名,本身已经代表地址了,为什么前面还有个取地址符号?
外面那个(char*)是不是强制类型转换?
好像不需要加啊?
s****y
发帖数: 4
20
来自主题: Programming版 - a simple C++ question
actually three:
1. what's the difference of
const char* p
char const *p
char* const p
what i understood is---first is a pointer to constant object;
second and third are same , a constant pointer to an object
am i right?
2. is this true:
const char* p = const char *p
3. why const char* can be both a character and a string declaration
i**p
发帖数: 902
21
来自主题: Programming版 - strcat()
char s1[] = "Hello ";
char s2[] = "world";
char *s3;
s3 = strcat(s1, s2);
It is Ok. Both s1 and s3 will be "Hello world".
char *s1 = "Hello ";
char s2[] = "world";
char *s3;
s3 = strcat(s1, s2);
It is runtime error. Can you explain?
c****n
发帖数: 105
22
来自主题: Programming版 - 这个C++程序为什么不能运行
I just did some test. See the program below:
===============================
#include
#include
#include
int main(int argc, char* argv[])
{
char *a="abcde";
char b[]="abcde";
char* c=(char*)malloc(6);
strcpy(c, a);
printf("%lx, %lx, %lx\n", a, b, c);
printf("%c %c %c\n", a[0], b[0], c[0]);
a[0] = 'f';
printf("%s\n", a);
return 0;
}
==============================
output:
80486d0, bfc74b96, 804b008
a a a
Segmentation fault
char *a="abcde", the compiler generate a str
K****n
发帖数: 5970
23
来自主题: Programming版 - 一个指向指针的指针的引用?
是不是通过,比如,char**& 来定义?以下代码在vc2008 cl name.cpp /Za编译:
#include
using namespace std;
void PtPtRef(char**& pprc){
(pprc)++;
}
int main(){
char c[] = {'A','B','C','D','E','F','G'};
char* pc=0;
for(int i=0; i pc = c+i;
cout<<*pc< PtPtRef(&pc);
cout<<*pc< }
return 0;
}
得:can not convert parameter 1 from 'char **' to 'char **&'
怎么改呢?
谢谢!
r****t
发帖数: 10904
24
奇怪,在连接的时候遇到如下错误,-lstdc++ 也没法成功,怎么办?
undefined reference to `operator<<(std::basic_string char>, std::allocator >&, int)'
undefined reference to `operator<<(std::basic_string char>, std::allocator >&, int)'
collect2: ld returned 1 exit status
E*****7
发帖数: 128
25
来自主题: Programming版 - 四道C++面试题
Four C++ interview questions (1), (2), (3) and (4) below:
char p[ ] = "C++ Interview Questions";
p[0] = "D"; // OK
char* p = "Shit C++ Interview Questions";
p[0] = "C"; // Error:(1) Why?
(2) What are the differences between char p[ ] and char* p? (3) When must
char p[ ] be used? (4) When must char* p be used?
T*****9
发帖数: 2484
26
来自主题: Programming版 - 四道C++面试题
C++有只读字符串池的
char *a = "hello";
char *b = "hello";
a和b指向的是同一个字符串,对于char *来说,对于C是合理的,对于C++,已经是被标
准认为不该存在当前的C++程序里面了,只是为了保证和C的兼容才有的,应该用的是
const char*,对于char *的修改是未定义行为
char a[]只是一个数组,
b***y
发帖数: 2799
27
来自主题: Programming版 - [合集] 偶写的itoa
☆─────────────────────────────────────☆
OverCloud (天马行空) 于 (Tue Mar 27 16:55:30 2007) 提到:
用的os没有itoa. 只好自己写了一个.
char * itoa(unsigned i, char *str, int redex)
{
static const char *LOOKUP = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

char holder;
char *p1, *p2;

if(redex > 0 && redex < sizeof(LOOKUP)/sizeof(char))
{
if (i == 0)
{
str[0] = '0';
str[1] = '\0';
}
else
{
p1 = str;

x*******j
发帖数: 17
28
来自主题: Programming版 - 问一道C++面试题
我的答案:用c#的,文不对题。

string mystring ="xxmxxmxmxxxxxxmxxmxxmx%";
// char [] a= new char [3]{'a','a','a'};
//char [] b= new char [3]{'b','b','b'};
//char aa = 'a';
int i=0;
int aflag = 0;
int bflag1 = 0;
int bflag2 = 0;
while (mystring[i] != '%')
{




Console.WriteLine("the string char is :{0}",mystring[i]);
i
j***i
发帖数: 1278
29
来自主题: Programming版 - Exceptional C++ code question
I copy the following code from the book and complied in gcc
struct ci_char_traits : public char_traits
// here it have errors
//
//
// error: expected template-name before ‘<’ token
// error: expected `{' before ‘<’ token
// error: expected unqualified-id before ‘<’ token
{
static bool eq( char c1, char c2 )
{ return toupper(c1) == toupper(c2); }
static bool lt( char c1, char c2 )
{ return toupper(c1) < toupper(c2); }
static int compare( const char* s1,
h****b
发帖数: 157
30
来自主题: Programming版 - 谁给解释一下这个c question
这类题见过几次了,都不太明白,哪位xdjm给说说?
先谢了
Char **array[12][12][12]
Referring to the array above, which one of the following definitions and
initializations ofp is valid?
char ***** p = array;
char * (* p) [12][12][12] = array;
const char ** p [12][12][12] = array;
char (** p) [12][12] = array;
char ** (* p) [12][12] = array;
m****s
发帖数: 1481
31
还是有点问题,大侠帮忙看下下面的代码,为什么在main里释放内存出错。
用pass by reference:
void fun1(int& *a, double& *b, char& *c){

a=new int[20];
b=new double[20];
c=new char[10];
for (int i=0;i<20;i++){
a[i]=i;
b[i]=sqrt((double)a[i]);
}
c="0123456789";
}
int _tmain(int argc, _TCHAR* argv[])
{
int *a;
double *b;
char *c;
fun1(a,b,c);
cout<<"a & b are:"< for(int i=0;i<20;i++)
cout< cout<<"c is: "< delete[] ... 阅读全帖
r*******y
发帖数: 1081
32
来自主题: Programming版 - string operator +
string library defines these overloaded operator +
string operator+ (const string& lhs, const string& rhs);
string operator+ (const char* lhs, const string& rhs);
string operator+ (char lhs, const string& rhs);
string operator+ (const string& lhs, const char* rhs);
string operator+ (const string& lhs, char rhs);
We know
string s = "hi" + "ji";
is not OK
If compiling this using g++ , I get the error :
invalid operands of types ‘const char [3]’ and ‘const char [3]’ to
binary ‘operator+’
I am a lit... 阅读全帖
d****n
发帖数: 1637
33
来自主题: Programming版 - 请教一道c/c++题
好吧,非要较真。
static in function .那块地方总是你的。
在你把临时内容取走之前,总是安全的。(前提是只有一个thread。多个thread就会有
麻烦。)
用多大,是你自己的事情。
你非要定义长度50, 拷贝100个字符,我也没办法。
用这个定义的最大的好处是--再你知道不会越界的前提下--每次不用分配内存空间。
你不会不知到malloc的时间要所消耗吧?
感兴趣的花自己作个benchmark.看看那个快。
char *func(){ static char * mychar[MAXCHAR]; ;;;; return mychar ;}
char *mallocFun(){chat *ret=(char *)malloc(sizeof(char)*MAXCHAR); return ret
;}
in main
main(){
{
int i;
for(i=0;i<100000;++i)
func();

}
{
int i;
for (i=0;i<100000;++i){
... 阅读全帖
d****n
发帖数: 1637
34
来自主题: Programming版 - 最新某公司onsite面试题 (转载)
1. I cant make sure.
but its outputs this
2,5
2. googled
1. const char *p : means p is pointer pointing to a constant char i.e.
you can not change the content of the location where it is pointing but u
can change the pointer itself to point to some other char.
2. char const *p, and char * const p : both are same & in this case p
is a constant pointer poiting to some char location. you can change the
contents of that location but u can't change the pointer to point to some
other locati... 阅读全帖
F*********k
发帖数: 42
35
好的,谢谢谢谢,我想我大概明白了,
我之前没看明白 FixedAllocator::Chunk::Deallocate 里边的
*toRelease = firstAvailableBlock_; 这句
其实这句实际上把当前和之前的连接起来了。
我把源码贴这里
void FixedAllocator::Chunk::Reset(std::size_t blockSize, unsigned char
blocks)
{
assert(blockSize > 0);
assert(blocks > 0);
// Overflow check
assert((blockSize * blocks) / blockSize == blocks);
firstAvailableBlock_ = 0;
blocksAvailable_ = blocks;
unsigned char i = 0;
unsigned char* p = pData_;
for (; i != blocks; p += blockSize)
... 阅读全帖
x******a
发帖数: 6336
36
来自主题: Programming版 - 请问关于overloading <<
I found if I make the second parameter const, i.e.std::ostream& operator<<(
std::ostream& os, const str& s), it worked now. what happened?
std::ostream& operator<<(std::ostream& os, str& s){
//obliterate existing value(s)
for (str::size_type i=0; i!=s.size(); ++i)
os<
return os;
}
class str{
public:
typedef std::vector::size_type size_type;
//constructors
str();
str(size_type n,char c);
str(const char* cp);
template str(In b, ... 阅读全帖
h*******3
发帖数: 3775
37
来自主题: Programming版 - 包子问使用C templates Sort data的问题
有一组数据,其中的fied有surname, department,payRate,等等
要求是按照surname 从A 到Z 排列这组数据。排列的方法是straight insertion
我现在的方法已经可以sort surname, department,但是如何能把他改成templates呢?
这样就能用来sort 任何数据。
我的目前sort的方法是这样的:
struct emp
{
char surname[15];
char given[15];
char depart[20];
double payRate;
char eyeColor[10];
};
void sort(struct emp person[], int nums, compare cmp, copy cpy)
{
void *key;
int j, i, flag;
struct emp temp;
for (j = 1; j < nums; j ++)
{
i = j - 1;
(*cpy)(key, (person + j));
te... 阅读全帖
n*****t
发帖数: 22014
38
来自主题: Programming版 - 狠偷懒狠偷懒的一个测试
我们蓝翔技校水平差,码的程序肯定错误百出,大家不许笑。
单进程,也不用锁了。5M 票,320M request,原始数据都是偷 memory 的,测试结果是
3 秒不到。request 前 2 bit 是 opcode,最后几位是 ticket ID。
1、我这个没搜空闲票,先声明一下。
2、IO 会多占一点时间,呵呵,不过估计也就多几秒的时间,懒得整太复杂了。
3、HW 就不提了,丢脸,唯一能透露的是 virtualpc
#include
#include
#include
#define SIZE 5*1024*1024
#define LOOPS 64
unsigned char tickets[SIZE];
unsigned long *reqs;
unsigned char *results;
int main() {
int i;
unsigned char op;
unsigned char *ticket;
unsigned long *... 阅读全帖
c******e
发帖数: 545
39
来自主题: Programming版 - C 语言,数字变字符,有点难度
除了别人的解法
1.用指针
short int num = 532;
char * c_ptr = (char*)(&num);
然后可以用c_ptr访问num的每个字节。little endian系统里,c_ptr[0]是LSB
2.逻辑运算
short int num = 532;
char LSB = (char)(num & 0xFF);
char MSB = (char)((num >> 8) & 0xFF);
这个不是数字变字符
B*********h
发帖数: 800
40
☆─────────────────────────────────────☆
laterbach (aa) 于 (Tue Mar 13 00:36:42 2007) 提到:
为什么下面的程序中,在子程序中指针p不是static的,返回主函数的也是正确值?
char *test(void)
{
char *p="hello";
return(p);
}
main()
{
char *s=NULL;
s=test();
printf("%s\n",s);
}
而在下面的程序中,在子程序中数组a就必须要用STATIC型,否则就出现内存被释放的问
题?
char *test(void)
{
static char a[]="hello";
return(a);
}
main()
{
char *s=NULL;
s=test();
printf("%s\n",s);
}
☆─────────────────────────────────────☆
Diadora (超级小马) 于 (Tue Mar 13 01:
r*******y
发帖数: 290
41
来自主题: JobHunting版 - 说说某著名软件公司的onsite面试
公司就不说了
面试一共见了4个人,都是上来就白板写程序,每人一道问题
1.写 char* strtok(char* str, const char* delimeter) code.
用法为:第一次调用 char* p = strtok(string, delimeter);
以后调用 p=strtok(NULL, delimeter);
关键:函数内部用static char* temp存储第一次pass的string
2.美国的coin设计为1,5,10,25,任意给定一个change,
用greedy algorithm可以算出最少所需要的coins,设计一套coins,
证明greedy algorithm给的solution不是最少的
然后在写一个algorithm,给定四个coin值,找出最少的coins数
数学上来说,min x1+x2+x3+x4 st. ax1+bx2+cx3+dx4=change
可以用DP
3. 给定5张牌,写一个函数判断是否是two pairs
4. 给定400个array,每个array有若干integers,找出这些array的
合集,交集,
w****t
发帖数: 33
42
来自主题: JobHunting版 - CS 面试题总结(5)
Debug the following code - explain the problems you find. Optionally, provid
e an
improved version.
#include
#include
char *gText = 0;
unsigned int gSize = 0; // the length of gText, in bytes
int append(const char* s )
{
if( s && s[0] )
{
if( (! gText) || (gSize = 0) )
{
gText = (char *)s;
gSize = strlen(s);
}
else
{
unsigned int len = gSize;
unsigned int s_len = strlen( s );
gSize += s_len;
char* temp = new char[ gSize ];
memcpy(temp, gText, len);
memcpy(temp + len, s, s_le
c****p
发帖数: 32
43
来自主题: JobHunting版 - 一个基本的string问题
大部分人只知道const char*指向的位置中的data不能改变,但是不知道char str2[]这
样到底是什么意思。
实际上,C有两种aggregation type,一种是struct,一种就是数组。
比如说,如果我们有
char s[] = {'s','t','r','i'};
那么s就是一个有4个character的buffer,实际上
char s[]={'a','b,'c',0};

char s[]="abc";
是等价的。
定义s的,不是后面那个"abc""string"(那只是operand而已),而是前面的
declaration,并不是说因为可以用指针指向数组,那么数组就可以是指针。
可以看看我copy的这一段:
http://www.codepp.com/default.aspx?g=posts&t=26

可以
我澄
s********a
发帖数: 1447
44
来自主题: JobHunting版 - 问个bit struct的面试题 急
请教一下 如何写一个struct
这个struct里面只有 4个项 每个占 1bit
我写了一个
struct {
unsigned char priority :1;
unsigned char nonpriority :1;
unsigned char empty :1;
unsigen char full :1;
}flag;
但是这个占了bit 因为是char
如何写这个struct只占4bit
谢谢
I**********s
发帖数: 441
45
来自主题: JobHunting版 - Google点面
问了1) 研究, 2) 多线程程序设计, 3) 任意无穷字符串流, 内存有限, 找出唯一一对
重复字符串, 这个我说了哈希表和外部排序, 但是面试人说有更好的办法(后来想也许
是bloom filter), 然后追问外部排序的细节到结束. 估计要挂 :(
总结: 面试既是技术活, 又是运气活.
无论如何, 把我的准备工作放下面, 攒点rp, 希望对大家有所帮助.
Interview Qs
Data Structures
1. Integer
- find number of 1s
- next largest smaller
- smallest larger number
- determine if is palindrom
- itoa, atoi
- add 2 numbers w/o using + or arithmetic operators
- implement *, -, / using only +
- find max of two numbers w/o co... 阅读全帖
h****b
发帖数: 157
46
来自主题: JobHunting版 - 1道brianbench 的题 c++
以下选哪一个
class String {
char *s;
int length;
public:
String(const char *);
String();
/* add code here */
};
int main()
{
String s1 = "abc";
String s2 = "def";

strcmp(s1, s2);
getchar();
return(1);
}
Referring to the sample code above, which one of the following member
functions do you add at the comment in order to allow the strcmp(s1, s2)
statement to compile?
operator const char*() const { return s; }
char* const operator() const { return s; }
operator char*
s*****n
发帖数: 5488
47
来自主题: JobHunting版 - 面经-facebook, amazon,telenav, quantcast
先写一个 函数加法:
private uint add(uint x, uint y, ref uint carrybit)
{
assert (x < 2 && y < 2 &7 carrybit <2);
uint ret = x^ y ^ carrybit;
carrybit = (x + y + carrbyit)/2;
return ret;
}
char[] strAdd(char[] a, char[] b)
{
int carry = 0;
char[] c= new char[max(a.length, b.length) + 1];
int len = min(a.Length, b.Length);
//compute the first part;
for (int i = 0, j= 0 ; i < len; i++, j++)
{
c[Length - 1 - j] = add(a[i] - '0',b[i] - '0',carry) + '0';
}
// compute ... 阅读全帖
i**********e
发帖数: 1145
48
来自主题: JobHunting版 - 面经-facebook, amazon,telenav, quantcast
你的代码好像有 bug,没有 '\0' 终止 string output.
我尝试写一下,思路跟两个数相加,不可利用 + operator 怎么做。
唯一一个问题就是 out = "0110",前面的 0 是无可避免,除非数组往前挪一位。
char *bstradd(char a[], char b[]) {
int n1 = strlen(a);
int n2 = strlen(b);
int len = max(n1, n2) + 1;
char *out = new char[len + 1];
out[len] = '\0';
int carry = 0;
for (int i = 0; i < len; i++) {
int dig1 = (i < n1) ? a[n1 - i - 1] - '0' : 0;
int dig2 = (i < n2) ? b[n2 - i - 1] - '0' : 0;
int sum = dig1 ^ dig2 ^ carry;
carry = (dig1 & dig2) | (di... 阅读全帖
d**e
发帖数: 6098
49
来自主题: JobHunting版 - 这道题好像有点难
careercup 150 上面好像有道类似的,但就是十进制加法。
我下面的解法结果的最高位有可能为0,比如101 + 1结果会出现0110
#include
#include
using namespace std;
char badd(int x, int y, int & carry)
{
int z;
int v = x + y + carry;
if(v == 0)
{
z = 0;
carry = 0;
}
else if(v == 1)
{
z = 1;
carry = 0;
}
else if(v == 2)
{
z = 0;
carry = 1;
}
else
{
z = 1;
carry = 1;
}
return '0' + z;
}
char * bstradd(char * a, char * b)
{
char * c = 0;
L*******e
发帖数: 114
50
来自主题: JobHunting版 - C++ Q: sizeof
What is the size of the following struct on 64-bit machines?
struct S1{
short a;
};
struct S2{
int a;
double b;
short c;
};
struct S3{
char a;
short b;
char c;
int d;
};
struct S4{
char a;
short s1;
char *pchar;
double d;
long l;
float f;
};
union U{
char *p;
short s;
long l;
};
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)