由买买提看人间百态

topics

全部话题 - 话题: mystr
1 (共1页)
w********s
发帖数: 1570
1
没人看出bug么?
class MyString {
private:
char* _data;
size_t _len;
void _init_data(const char *s) {
_data = new char[_len+1];
memcpy(_data, s, _len);
_data[_len] = '\0';
}
public:
MyString() {
_data = NULL;
_len = 0;
}
MyString(const char* p) {
_len = strlen (p);
_init_data(p);
}
MyString(const MyString& str) {
_len = str._len;
_init_data(str._data);
std::cout << "Copy Constructor is called! source: " << str._data << std:
:endl;
}
MyStri... 阅读全帖
n*s
发帖数: 752
2
来自主题: JobHunting版 - Epic Written Interview
4. string transpose
import sys
def transpose(input,i):
mystr = list(input)
mystr[i],mystr[i+1] = mystr[i+1],mystr[i]
return ''.join(mystr)
def str_transpose():
print 'input two strings, separated by blank:'
a, b = sys.stdin.readline().split()
size = len(a)
if size != len(b) or sorted(a) != sorted(b):
return 'no way!'
next = [b]
parent = {b:None}
idx = size -1
notFound = True
while notFound:
newstr = []
for x in next:
... 阅读全帖
n*s
发帖数: 752
3
来自主题: JobHunting版 - Epic Written Interview
4. string transpose
import sys
def transpose(input,i):
mystr = list(input)
mystr[i],mystr[i+1] = mystr[i+1],mystr[i]
return ''.join(mystr)
def str_transpose():
print 'input two strings, separated by blank:'
a, b = sys.stdin.readline().split()
size = len(a)
if size != len(b) or sorted(a) != sorted(b):
return 'no way!'
next = [b]
parent = {b:None}
idx = size -1
notFound = True
while notFound:
newstr = []
for x in next:
... 阅读全帖
x******a
发帖数: 6336
4
来自主题: JobHunting版 - 请问关于overloading << (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: xiaojiya (xiaojiya), 信区: Programming
标 题: 请问关于overloading <<
发信站: BBS 未名空间站 (Wed Feb 27 11:59:50 2013, 美东)
I am working on the example in accelerated C++.
I have overloaded operator+= , operator+ , and operator<<.
the following code does not work.
I got "invalid operands to binary expression('ostream'(aka 'basic_ostream<
char>') and 'myString') when compiling the code.
myString s1="hello";
myString s2="world";
std::cout<< s1+s2 < it worked in the foll... 阅读全帖
x******a
发帖数: 6336
5
来自主题: Programming版 - 请问关于overloading <<
I am working on the example in accelerated C++.
I have overloaded operator+= , operator+ , and operator<<.
the following code does not work.
I got "invalid operands to binary expression('ostream'(aka 'basic_ostream<
char>') and 'myString') when compiling the code.
myString s1="hello";
myString s2="world";
std::cout<< s1+s2 < it worked in the following way.
myString s1="hello";
myString s2="world";
myString s=s1+s2;
std::cout<< s < what should I do to make the first one work... 阅读全帖
l*********8
发帖数: 4642
6
来自主题: JobHunting版 - 这个拷贝构造函数有什么问题?
Thank you for the comments.
I modified my code. But I still like the initialization list :-)
class MyStr {
MyStr() : data(NULL), size(0)
{
}
~MyStr()
{
if (data != NULL)
delete [] data;
}
MyStr(const MyStr& original) : data(NULL), size(0)
{
data = new char[original.size+1];
if(original.data == NULL)
return;
memcpy(data, original.data, original.size);
data[original.size] = '\0';
size = original.size;
}
private:
char* data;
int size;
}
h**k
发帖数: 3368
7
MyStringArray[0] = MyString.substring(0, MyString.find(';') );
MyString.erase(0, MyString.find( ';' ) );

a
l*********8
发帖数: 4642
8
来自主题: JobHunting版 - 这个拷贝构造函数有什么问题?
class MyStr {
MyStr() : data(NULL), size(0)
{
}
MyStr(const MyStr& original) : data(NULL), size(0)
{
p = new char[original.size+1];
if (!p || !(original.data))
throw exception;
memcpy(p, original.data, original.size);
p[original.size] = '\0';
data = p;
size = original.size;
}
private:
char* data;
int size;
}
m***n
发帖数: 2154
9
来自主题: JobHunting版 - 这个拷贝构造函数有什么问题?
MyStr::MyStr(const MyStr& original)
{
p = new char[original.size+1];
memcpy(p, original.data, original.size);
p[original.size] = '\0';
}
char* data;
int size;
谢谢。更新了一下 ,还有问题么?
更新了成员变量。
c*****n
发帖数: 96
10
来自主题: JobHunting版 - 这个拷贝构造函数有什么问题?
MyStr::MyStr(const MyStr& original)
{
p = new char[original.size+1];
memcpy(p, original.data, original.size);
==> p[original.size+1] = '\0';
}
There is a buffer overflow issue. Should be p[original.size] = '\0'
t*******2
发帖数: 182
11
一老印,电面迟到15分钟,打过来也不花两分钟介绍一下team之类的,直接上题。。
1) Can you explain dependency injection with an example, in java.
我一下子懵了,听都没听说过这个东西,什么也扯不出来,只好老实承认没听说过。。
事后google了一下,好像是Spring framework里面的一个概念。。
2) Can you create memory leak with a sample program.
也是完全没准备过,想了两分钟想不出什么来,老印直接开始问下题
3) What do you think is the output of this sample program
public class MyThread implements Runnable {
String myString = "Yes ";
public void run() {
this.myString = "No ";
}
public static void main(String[] args) {
MyThread t ... 阅读全帖
f*******t
发帖数: 7549
12
大家来测试一下到底多少个Yes和No吧。加不加volatile关键字对结果有影响哦!
public class MyThread implements Runnable {
volatile String myString = "Yes";
public void run() {
this.myString = "No";
}

public static void main(String[] args) {
AtomicInteger[][] counts = new AtomicInteger[10][2];
for (int i = 0; i < 10; i++)
for (int j = 0; j < 2; j++)
counts[i][j] = new AtomicInteger(0);
Thread[] threads = new Thread[1000];
for (int i = 0; i < 10... 阅读全帖
l**********r
发帖数: 4612
13
【 以下文字转载自 JobHunting 讨论区 】
发信人: tarotaro2 (taro), 信区: JobHunting
标 题: 上个Yahoo电面面经, 给恶心坏了。。
发信站: BBS 未名空间站 (Thu Sep 12 14:33:48 2013, 美东)
一老印,电面迟到15分钟,打过来也不花两分钟介绍一下team之类的,直接上题。。
1) Can you explain dependency injection with an example, in java.
我一下子懵了,听都没听说过这个东西,什么也扯不出来,只好老实承认没听说过。。
事后google了一下,好像是Spring framework里面的一个概念。。
2) Can you create memory leak with a sample program.
也是完全没准备过,想了两分钟想不出什么来,老印直接开始问下题
3) What do you think is the output of this sample program
public class MyThread implements ... 阅读全帖
l*****e
发帖数: 3343
14
来自主题: Database版 - VBA Dropdown List 求教
dim myRng as range
range("A1").select
dim myStr as string
For i=1 to 3
set myrng=activecell.offset(4,3*I-2)
myStr="=" & myrng.address
With cells(1,3*i-1).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=myStr
End With
Next I
x*******j
发帖数: 17
15
来自主题: 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
b******a
发帖数: 215
16
来自主题: Programming版 - 急!问个有关aligment的问题。
嵌入式系统的CPU,对aligment要求很严。编译器是gcc。
函数要求传入一个(void *str)进去,然后函数里面会每2个byte读到一个local的变量
里面。
现在的问题是如果设一个变量如: char *mystr="this is my str"; 然后把mystr传入
函数,有时间mystr不是按照2或者4来对齐的,这样函数内部就会出错,导致系统崩溃。
因为一般情况下,char是没法对齐的。请问gcc下面有没有什么编译选项可以强制每个
变量都是按照 2或者4来对齐的?程序要求不能用pragma之类的语句来对齐。
谢谢了。
a****l
发帖数: 8211
17
有一个字符串,要在尾巴上加一个ascii码为13(dec)的字符,该怎么写??
Dim MyStr(10) As String
MyStr = "abcd"
现在要把MyStr变成abcd(ascii 13的字符)
应该是很简单的吧?新手不懂,谢谢指教!
c**********e
发帖数: 2007
18
【 以下文字转载自 Programming 讨论区 】
发信人: careerchange (Stupid), 信区: Programming
标 题: How to convert string to string array (or vector)
发信站: BBS 未名空间站 (Mon Sep 13 19:18:21 2010, 美东)
It looks that`in Java, there is a function Split which convert a string to a
string array. I wonder if we could do the same in C++. How to do the
conversion?
string MyString = "value1;value2;value3;value4;"
string[] MyStringArray = MyString.Split(';');
MyStringArray[0] (would give value1)
MyStringArray[1] (would give value2)
l*****a
发帖数: 14598
19
来自主题: JobHunting版 - 这个拷贝构造函数有什么问题?
你为什么要保留没有意义的code?
btw, if u really want to keep them,
I suggest u just keep
MyStr(const MyStr& original) : size(original.size)
l*********8
发帖数: 4642
20
来自主题: JobHunting版 - 这个拷贝构造函数有什么问题?
MyStr(const MyStr& original)
{
if(original.data == NULL) {
data = NULL;
size = 0;
return;
}
data = new char[original.size+1];
memcpy(data, original.data, original.size);
data[original.size] = '\0';
size = original.size;
}
x*******9
发帖数: 138
21
来自主题: JobHunting版 - 贡献一道电面题
这题如果允许特殊分割符的话,非常简单。
serialize:
mystr = '\1'.join(str_list)
deserialize:
mystr.split('\1')
如果不允许的话,可以使用protobuf那种varient integer的方式。也可以用一个固定
长度的“字段”存字符串大小。
这题感觉没啥意思,算是考察知识广度?
h*****n
发帖数: 439
22
来自主题: BuildingWeb版 - ASP 一问,急!
Dim MyString, LeftString, OutputString
.
.
.
LeftString = Left ( MyString, 10 )
OutputString = LeftString & "..."
T*****e
发帖数: 361
23
myString.split("\\sd", 2);
or myString.split("\\\\sd", 2) if your '\sd' is not a pattern.
b***i
发帖数: 3043
24
我有一个类叫storage,其中有个数组string ok[100];
还有个acquirereference(int a)想返回ok[a]的引用,比如我在主程序中
storage m;
string& mystring=m.acquirereference(10);
mystring="ok";
可以让ok[10]获得"ok"。 应该怎样写呢?
a****i
发帖数: 1182
25
try
public class Storage {
String[] ok;
public set(int index, String value) {
ok[index] = value;
}
}
class Main {
public static void main (String[] args) {
Storeage m = new Storeage();
String mystring = "ok";
m.set(10, mystring);
}
}
there is no way to get the reference and assign it.
String objects are immutable.
o******r
发帖数: 259
26
Sorry,记错了,
当需要access两个class的 private data时用friend function.
另外,当操作符左边是class object的时候, 才会调用class member,
否则用friend function,
比如2个String相加,
String myStr;
"abcd" + myStr 最好定义friend function
c**********e
发帖数: 2007
27
It looks that`in Java, there is a function Split which convert a string to a
string array. I wonder if we could do the same in C++. How to do the
conversion?
string MyString = "value1;value2;value3;value4;"
string[] MyStringArray = MyString.Split(';');
MyStringArray[0] (would give value1)
MyStringArray[1] (would give value2)
etc......
s*****w
发帖数: 1527
28
hi, i have a char array like this,
char array[0]='a', array[1]='b', array[2]='c';
string myStr = array.ToString();
myStr is not "abc", why ?
c*****t
发帖数: 1879
29
Mine lists filenames containing mystr.
Yours lists files in which the contents contain mystr.
Actually, ls -1 is completely unnecessary since * is
all one needs.
R*********i
发帖数: 7643
30
来自主题: Statistics版 - 菜鸟问题 (R & SAS)
A not-so-straightforward but working solution in SAS:
data test;
mystr='abcdef ghijklnopaijeiajig aeioajgeojgajipa aweg rrr eagaggeagg
awgae gawegwgaaag aewh aawgah';
newstr=compress(mystr);
l=length(newstr);
output;
run;
proc sql;
select left(put(ceil(l/10),4.)) into :len from test;
quit;
data test2;
length newvar1 - newvar&len $10;
set test;
array newvar [*] $ newvar1 - newvar&len;
do i=1 to dim(newvar);
newvar[i]=substr(newstr,1+10*(i-1),10);
end;
drop i newstr;
run... 阅读全帖
f********t
发帖数: 6999
31
【 以下文字转载自 JobHunting 讨论区 】
发信人: winetricks (winetricks), 信区: JobHunting
发信站: BBS 未名空间站 (Sat Mar 22 10:46:35 2014, 美东)
http://www.ibm.com/developerworks/cn/aix/library/1307_lisl_c11/
以一个简单的 string 类为示例,实现拷贝构造函数和拷贝赋值操作符。
示例程序 :
class MyString {
private:
char* _data;
size_t _len;
void _init_data(const char *s) {
_data = new char[_len+1];
memcpy(_data, s, _len);
_data[_len] = '
c*****e
发帖数: 737
32
假设你可以使用一个MyDateTime类,有如下方法:
static MyDateTime now ()
MyDateTime & decrementHour (const rwint64 h)
MyDateTime & decrementMinute (const rwint64 m)
MyDateTime & decrementSecond (const rwint64 s)
MyString& getDate()
l******d
发帖数: 530
33
来自主题: JobHunting版 - 这个拷贝构造函数有什么问题?
p, origin.data是不是都要检测null?MyStr的成员定义有没有列出来?
s*******u
发帖数: 220
34
来自主题: JobHunting版 - cc150 string基础疑惑:1.5 and 1.8
java刚上手,看cc150有些迷糊:
1.5
line 9: mystr += last + "" + count; 这里为啥要插入“”?
1.8
isSubstring解法感觉有点想必要非充分,不是很可信,不知道可靠否。
u****0
发帖数: 155
35
来自主题: JobHunting版 - cc150 string基础疑惑:1.5 and 1.8
last和count都是int嗎?如果是的話,不加"",會先算last+count,再加到mystr後面
w********s
发帖数: 1570
36
http://www.ibm.com/developerworks/cn/aix/library/1307_lisl_c11/
以一个简单的 string 类为示例,实现拷贝构造函数和拷贝赋值操作符。
示例程序 :
class MyString {
private:
char* _data;
size_t _len;
void _init_data(const char *s) {
_data = new char[_len+1];
memcpy(_data, s, _len);
_data[_len] = '
f****4
发帖数: 1359
37
原标题是C++11 标准新特性: 右值引用与转移语义
我的理解是这个MyString只是用来示例用的。
要是把_init_data里面_data delete掉,用了右值引用与转移_data应该是undefined/
invalid状态
f********t
发帖数: 6999
38
【 以下文字转载自 Military 讨论区 】
发信人: fuckthrust (...), 信区: Military
标 题: IBM高级软件工程师老印的示例代码,大家看看有多少个bug? (转载)
发信站: BBS 未名空间站 (Sat Mar 22 22:58:24 2014, 美东)
发信人: winetricks (winetricks), 信区: JobHunting
发信站: BBS 未名空间站 (Sat Mar 22 10:46:35 2014, 美东)
http://www.ibm.com/developerworks/cn/aix/library/1307_lisl_c11/
以一个简单的 string 类为示例,实现拷贝构造函数和拷贝赋值操作符。
示例程序 :
class MyString {
private:
char* _data;
size_t _len;
void _init_data(const char *s) {
_data = new char[_len+1];
memcpy(_data, s, _len);
... 阅读全帖
f********t
发帖数: 6999
39
【 以下文字转载自 Military 讨论区 】
发信人: fuckthrust (...), 信区: Military
标 题: IBM高级软件工程师老印的示例代码,大家看看有多少个bug? (转载)
发信站: BBS 未名空间站 (Sat Mar 22 22:58:24 2014, 美东)
发信人: winetricks (winetricks), 信区: JobHunting
发信站: BBS 未名空间站 (Sat Mar 22 10:46:35 2014, 美东)
http://www.ibm.com/developerworks/cn/aix/library/1307_lisl_c11/
以一个简单的 string 类为示例,实现拷贝构造函数和拷贝赋值操作符。
示例程序 :
class MyString {
private:
char* _data;
size_t _len;
void _init_data(const char *s) {
_data = new char[_len+1];
memcpy(_data, s, _len);
... 阅读全帖
l*****e
发帖数: 3343
40
来自主题: Database版 - VBA Dropdown List 求教
should be:
myStr="=" & Range(myRng, myRng.end(xldown)).address
t****t
发帖数: 6806
41
来自主题: Programming版 - 问个Excel VBA 的问题
mystr &= chr(13)
PS: VB is stupid
a***y
发帖数: 2803
42
来自主题: Programming版 - 有熟悉php的吗?问个文本处理
echo preg_replace("/^([Cc][Hh][Ii][Nn][Aa])$/","$1",$mystring);
可以显示替换后的string.
d*******3
发帖数: 6550
43
来自主题: Programming版 - 有熟悉php的吗?问个文本处理
很简单啊,
echo preg_replace("/^(.*)(china)(.*)$/i","$1$2$3",$mystring);
同一个单词不区分大小写匹配就行了,如果是变量就把china 换成变量就可以了
b*******s
发帖数: 5216
44
【 以下文字转载自 Joke 讨论区 】
发信人: fuckthrust (...), 信区: Joke
标 题: IBM高级软件工程师老印的示例代码,大家看看有多少个bug? (转载 (转载)
发信站: BBS 未名空间站 (Sat Mar 22 22:59:37 2014, 美东)
发信人: fuckthrust (...), 信区: Military
标 题: IBM高级软件工程师老印的示例代码,大家看看有多少个bug? (转载)
发信站: BBS 未名空间站 (Sat Mar 22 22:58:24 2014, 美东)
发信人: winetricks (winetricks), 信区: JobHunting
发信站: BBS 未名空间站 (Sat Mar 22 10:46:35 2014, 美东)
http://www.ibm.com/developerworks/cn/aix/library/1307_lisl_c11/
以一个简单的 string 类为示例,实现拷贝构造函数和拷贝赋值操作符。
示例程序 :
class MyString {
private:
char... 阅读全帖
F***Q
发帖数: 6599
45
I got it,thx
but I still wonder how can I get the purpose by using ls as
ls -1 | grep mystr
which can list all of the files, then, how to delete them?
only can find exec another command?
c*****t
发帖数: 1879
46
1. find could do the job as well :) Mastering find is invaluable.
2. Learn to use backquote.
rm `ls -1 | grep mystr`
t*********l
发帖数: 30
47
I think this won't work. should be
rm `ls -1 | xargs grep -l mystr`
m*****e
发帖数: 4193
48

You don't want to do that. Try to think simple:
rm -f *mystr*
1 (共1页)