由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Microsoft interview question
相关主题
懒得写了,想练手的就写写贴在这里吧leetcode的新题是1337c0d3r本人在更新吗?
为什么我这段简单的程序segment fault贡献G家电面面经
map numbers to stringsC的argc问题
MapReduce的面试题c++ 程序一问
perl Question 请教large file的一道题
也报个G家intern面经跪求roman number to integer 和 integer to roman number的程序
贡献一道题一道C语言题
Groupon新鲜面经一道面试题,请大家给些意见
相关话题的讨论汇总
话题: string话题: char话题: int话题: str话题: end
进入JobHunting版参与讨论
1 (共1页)
a********r
发帖数: 218
1
Question:
reverse the string based on the word (or you can understand as reversing
words), for example,
Input string: I Am Engineer
Output string shall be: Engineer Am I
我是菜鸟, 那位达人能用C/C++编码一下,跪谢!
B*****g
发帖数: 34098
2
自己搜搜吧,这个是老题了。

【在 a********r 的大作中提到】
: Question:
: reverse the string based on the word (or you can understand as reversing
: words), for example,
: Input string: I Am Engineer
: Output string shall be: Engineer Am I
: 我是菜鸟, 那位达人能用C/C++编码一下,跪谢!

l*****a
发帖数: 559
3
no offence.
if you cannot find a solution to this question, you shall not apply a sde in
MS.
a********r
发帖数: 218
4
你能不能帮忙给个答案呢

【在 B*****g 的大作中提到】
: 自己搜搜吧,这个是老题了。
a********r
发帖数: 218
5
I agree, could you please code it if it does not bother you too much?

in

【在 l*****a 的大作中提到】
: no offence.
: if you cannot find a solution to this question, you shall not apply a sde in
: MS.

s********x
发帖数: 914
6
// input I AM Engineer
// output Engineer AM I
public static char[] reverseWordinString(char[] string){
char[] result = new char[string.length];
int k = 0;
for (int i = string.length-1; i >=0 ; ){
if (!isWord(string[i])) {
int j = i;
while (j>=0&&!isWord(string[j])) j-- ;
if (j==0 && !isWord(string[0]))
result[k++] = string[0];
for (int t = j + 1 ; t <= i ; t ++)
result[k++] = string[t];
i = j;
} else{
int j = i;
while (j>=0&&isWord(string[j])) j-- ;
if (j==0 && isWord(string[0]))
result[k++] = string[0];
for (int t = j + 1 ; t <= i ; t ++)
result[k++] = string[t];
i = j;
}
}
return result;
}
private static boolean isWord(char c) {
if ( (int) c >= (int) 'a' && (int) c <= (int) 'z')
return true;
if ( (int) c >= (int) 'A' && (int) c <= (int) 'Z')
return true;
return false;
}

【在 a********r 的大作中提到】
: I agree, could you please code it if it does not bother you too much?
:
: in

s********x
发帖数: 914
7
String s = "Hello, my name is John";
char[] r = reverseWordinString(s.toCharArray());
for (int i = 0 ; i< r.length; i++){
System.out.print(r[i]);
}
John is name my, Hello

【在 s********x 的大作中提到】
: // input I AM Engineer
: // output Engineer AM I
: public static char[] reverseWordinString(char[] string){
: char[] result = new char[string.length];
: int k = 0;
: for (int i = string.length-1; i >=0 ; ){
: if (!isWord(string[i])) {
: int j = i;
: while (j>=0&&!isWord(string[j])) j-- ;
: if (j==0 && !isWord(string[0]))

s********x
发帖数: 914
8
有包子没?

【在 s********x 的大作中提到】
: String s = "Hello, my name is John";
: char[] r = reverseWordinString(s.toCharArray());
: for (int i = 0 ; i< r.length; i++){
: System.out.print(r[i]);
: }
: John is name my, Hello

S**I
发帖数: 15689
9
LZ ask for C/C++, not C#.

【在 s********x 的大作中提到】
: 有包子没?
j**l
发帖数: 2911
10
Programming Interview Exposed
相关主题
也报个G家intern面经leetcode的新题是1337c0d3r本人在更新吗?
贡献一道题贡献G家电面面经
Groupon新鲜面经C的argc问题
进入JobHunting版参与讨论
a********r
发帖数: 218
11
Thanks a lot!
But I need an implementation using C/C++, you cannot even use STL. Also, it
is better to use in place replacement.

【在 s********x 的大作中提到】
: 有包子没?
S**I
发帖数: 15689
12
#include
#include
void reverseStr(char str[], int begin, int end){

char temp;

while(end > begin){
temp = str[begin];
str[begin++] = str[end];
str[end--] = temp;
}
}
void reverseWord(char str[]){

int begin = 0, end = 0, length = (int) strlen(str) - 1;

reverseStr(str, begin, length);

while(end < length){

if(str[end] != ' '){

begin = end;

while(end < length && str[end] != ' ')
end++;

reverseStr(str, begin, end - 1);

}
end++;
}
}
int main(int argc, const char* argv[])
{

char str[100];

strcpy(str, argv[1]);

reverseWord(str);

printf("%s", str);

}

【在 a********r 的大作中提到】
: Question:
: reverse the string based on the word (or you can understand as reversing
: words), for example,
: Input string: I Am Engineer
: Output string shall be: Engineer Am I
: 我是菜鸟, 那位达人能用C/C++编码一下,跪谢!

h*********n
发帖数: 11319
13
i believe the output should depend on how the interviewer would like to trea
t ' ' (or other delimiters)
string reverseByWord(string in){
string out;
string::iterator s = in.end();
string::iterator e = in.end();
while(s!=in.begin()){
e = s;
s--;
while((*s != ' ')&&(s != in.begin())){
s--;//strops at space
}

string::iterator cur = s;
if(s!=in.begin())
cur++;

for(;cur!=e; cur++)
out.push_back(*cur);
if(s!=in.begin())
out.push_back(' ');
}
return out;
}

【在 s********x 的大作中提到】
: 有包子没?
W****X
发帖数: 84
14
先把整个字符串倒序,再把每个单词倒序
a********r
发帖数: 218
15
Thanks SETI!

【在 S**I 的大作中提到】
: #include
: #include
: void reverseStr(char str[], int begin, int end){
:
: char temp;
:
: while(end > begin){
: temp = str[begin];
: str[begin++] = str[end];
: str[end--] = temp;

l*****a
发帖数: 559
16
There need to have a minor change.
From
while(end < length && (str[end] != ' '))
end++;
To
while(end <= length && (str[end] != ' '))
end++;

【在 S**I 的大作中提到】
: #include
: #include
: void reverseStr(char str[], int begin, int end){
:
: char temp;
:
: while(end > begin){
: temp = str[begin];
: str[begin++] = str[end];
: str[end--] = temp;

a********r
发帖数: 218
17
我是菜鸟,Lanmama 达人:
Can you implement it with in-place word-by-word swapping? for example,
considering using two pointers, one move from left to right, another move
from right to left.

【在 l*****a 的大作中提到】
: There need to have a minor change.
: From
: while(end < length && (str[end] != ' '))
: end++;
: To
: while(end <= length && (str[end] != ' '))
: end++;

d**e
发帖数: 6098
18
前面SETI的不是in-place?

【在 a********r 的大作中提到】
: 我是菜鸟,Lanmama 达人:
: Can you implement it with in-place word-by-word swapping? for example,
: considering using two pointers, one move from left to right, another move
: from right to left.

S**I
发帖数: 15689
19
you're right, just changed.

【在 l*****a 的大作中提到】
: There need to have a minor change.
: From
: while(end < length && (str[end] != ' '))
: end++;
: To
: while(end <= length && (str[end] != ' '))
: end++;

a********r
发帖数: 218
20
Yes, SETI's is in-place and char-by-char swapping. possible to word-by-word
swapping?

【在 d**e 的大作中提到】
: 前面SETI的不是in-place?
d**e
发帖数: 6098
21
做法都这样的,直接换word不行

word

【在 a********r 的大作中提到】
: Yes, SETI's is in-place and char-by-char swapping. possible to word-by-word
: swapping?

f********3
发帖数: 210
22
我也是新人,呵呵。不过刚好做过这道题。
有包子没?=D
#include
using namespace std;
using std::string;
char *reverseEachword(char *src, int len)
{
char *p = src, *q = src + len - 1;
char tmp;
while(p < q)
{
tmp = *p;
//src[0] = 'z';
*p = *q; // why this step is wrong?
*q = tmp;
p++;
q--;
}
return src;
}
char *reverseWholeStr(char *srcstr, int len)
{
char *p = srcstr, *q;
int count;
while(*p != '\0')
{
count = 0;
q = p;
while(*q != ' ' && *q != '\0')
{
q++;
count++;
}
reverseEachword(p, count);
if(*(p+count) != '\0')
p += count+1;
else
p += count;
}
return srcstr;
}
int main()
{
char ss[] = "Hello this is Bob";
char *t = reverseEachword(ss, 17);
char *dst = reverseWholeStr(t, 17);
for(char *p = dst; *p != '\0'; p++)
cout<<*p;
cout< }

as reversing

【在 a********r 的大作中提到】
: Question:
: reverse the string based on the word (or you can understand as reversing
: words), for example,
: Input string: I Am Engineer
: Output string shall be: Engineer Am I
: 我是菜鸟, 那位达人能用C/C++编码一下,跪谢!

1 (共1页)
进入JobHunting版参与讨论
相关主题
一道面试题,请大家给些意见perl Question 请教
问题:从电话号码打出所有单词也报个G家intern面经
ebay第一轮电话面经贡献一道题
AMAZON onsite 3月面经Groupon新鲜面经
懒得写了,想练手的就写写贴在这里吧leetcode的新题是1337c0d3r本人在更新吗?
为什么我这段简单的程序segment fault贡献G家电面面经
map numbers to stringsC的argc问题
MapReduce的面试题c++ 程序一问
相关话题的讨论汇总
话题: string话题: char话题: int话题: str话题: end