今天创新工厂的笔试题...

southbirdfly 2009-10-21 01:12:37
很基本,但感觉还是做得不好,大家就当练习,贴出你们的解法..

1、单词的反转,比如"I love this game" 反转后为"game this love i"
2、输入任意一个正整数n,输出比它大的最小质数。
3、给一个数组,构造一棵平衡二叉树。


PS:昨天见到李开复,精神很好,看来离开谷歌后混得不错,呵呵..
...全文
2769 127 打赏 收藏 转发到动态 举报
写回复
用AI写文章
127 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2011-04-25
  • 打赏
  • 举报
回复
第2题:
输入1能得到2吗?
输入1111111111111111111111111111111111111111111111111111111,答案是?
lan243675044 2011-04-25
  • 打赏
  • 举报
回复
那只是个结束符而已 我想问的是为什么我的程序要按两次ctrl+z才回结束 你是用什么编译器编译的?
cumt_TTR 2011-04-23
  • 打赏
  • 举报
回复
[Quote=引用 123 楼 cumt_ttr 的回复:]

引用 116 楼 lan243675044 的回复:

我写了下第一题的代码,大家帮我分析下,程序可以运行成功,但是为什么老是要用连续ctrl+z两次才能结束啊!
#include<iostream>
using namespace std;
#include <string>
void show(...);
int main(void)
{
cout<<"请输入字符: "<<……
[/Quote]
不是空格,MS是个CTRL+Z
cumt_TTR 2011-04-23
  • 打赏
  • 举报
回复
[Quote=引用 103 楼 wanggang999 的回复:]

又写了一个第一题,如果分隔符只有空格,并且都是单个空格,就没问题:
C/C++ code
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;

typedef vector<string> StrArray;

……
[/Quote]
也用vector,也只能处理单个空格
cumt_TTR 2011-04-23
  • 打赏
  • 举报
回复
[Quote=引用 116 楼 lan243675044 的回复:]

我写了下第一题的代码,大家帮我分析下,程序可以运行成功,但是为什么老是要用连续ctrl+z两次才能结束啊!
#include<iostream>
using namespace std;
#include <string>
void show(...);
int main(void)
{
cout<<"请输入字符: "<<endl;
show();
return 0;
……
[/Quote]
你这代码真巧妙,我只需要按一次 CTRL+Z就可以了,DEV-CPP
但是你在game前面也输出了一个空格
kobe198702 2011-04-21
  • 打赏
  • 举报
回复
都很简单,考虑的是创新吧
wesweeky 2011-04-21
  • 打赏
  • 举报
回复
第一个是面试宝典上的
先对整个翻转 再对翻转后的每个单词翻转
写一个函数就好
libralibra 2011-04-21
  • 打赏
  • 举报
回复
马克

我不为楼主这样的标题所吸引,也不是被帖子的内容所迷惑。
我不是来抢沙发的,也不是来打酱油的。
我不是为楼主呐喊加油的,也不是对楼主进行围堵攻击的。
我只是为了每天的银币而默默奋斗。

你是个美女,我毫不关心,你是个怪兽,我决不在意;
你是个帅哥,我不会妒忌,你是个畜男,我也不会BS。
你的情操再怎么高尚,我也不会赞美;
你的道德如何沦丧,我也不为所动。

在这个处处都要银币的时代,不得不弄个牛B的数字来显眼,
于是我抄下了这段话,专门用来回帖,好让我每天有固定的积分收入。
cumt_TTR 2011-04-20
  • 打赏
  • 举报
回复
第一个题,觉得自己写的有些矬。。。。

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstdlib>

int main()
{
using namespace std;
cout<<"Please enter a word:\n";
string line;
getline(cin,line);
istringstream stem(line);
string s;
vector<string> svec;
while(stem>>s)
svec.push_back(s);
reverse(svec.begin(),svec.end());
line.clear();
for(int i=0;i!=svec.size();++i)
{ if(i!=svec.size()-1)
line=line+svec[i]+" ";
else
line=line+svec[i];
}
cout<<line<<endl;
system("pause");
}

====================================
大家指点下,假设每个单词中只有一个空格。。。。
lan243675044 2011-04-20
  • 打赏
  • 举报
回复
是不是编译器的问题啊
lan243675044 2011-04-20
  • 打赏
  • 举报
回复
我写了下第一题的代码,大家帮我分析下,程序可以运行成功,但是为什么老是要用连续ctrl+z两次才能结束啊!
#include<iostream>
using namespace std;
#include <string>
void show(...);
int main(void)
{
cout<<"请输入字符: "<<endl;
show();
return 0;
}
void show(...)
{
string str;
cin>>str;
if(cin)
show();
cout<<str<<' ';
}
新铺村长 2011-04-19
  • 打赏
  • 举报
回复
都是高手!差距还很大!
nana 2011-04-19
  • 打赏
  • 举报
回复
请问?都能做出来,那谁上??
meditator_bi 2011-04-19
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <assert.h>
#include <string>
char *ReverseChars(char *begin, char *end) {
assert(NULL != begin && "ReverseChars()");
assert(NULL != end && "ReverseChars()");
--end;
char *p = begin;
while (begin < end) {
char c = *begin;
*begin = *end;
*end = c;
++begin, --end;
}
return p;
}

char *ReverseWords(char *words)
{
assert(NULL != words && "ReverseWords()");
ReverseChars(words, words+strlen(words));
char *word_head = words;
for(char *word_tail = NULL; NULL != (word_tail = strchr(word_head, ' ')); word_head = ++word_tail)
ReverseChars(word_head, word_tail);
return words;
}

int main(int argc, char *argv[])
{
char str[] = "I love this game";
printf("%s\n", str);
ReverseWords(str);
printf("%s\n", str);
return 0;
}
meditator_bi 2011-04-19
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <assert.h>
#include <string>
char *ReverseChars(char *begin, char *end) {
assert(NULL != begin && "ReverseChars()");
assert(NULL != end && "ReverseChars()");
--end;
char *p = begin;
while (begin < end) {
char c = *begin;
*begin = *end;
*end = c;
++begin, --end;
}
return p;
}

char *ReverseWords(char *words)
{
assert(NULL != words && "ReverseWords()");
char *p = words;
ReverseChars(words, words+strlen(words));
char *world_head = words;
char *world_tail = strchr(words, ' ');
while(NULL != world_tail) {
ReverseChars(world_head, world_tail);
world_head = world_tail + 1;
world_tail = strchr(world_head, ' ');
}
return p;
}

int main(int argc, char *argv[])
{
char str[] = "I love this game";
printf("%s\n", str);
ReverseWords(str);
printf("%s\n", str);
return 0;
}
eye_119_eye 2011-04-19
  • 打赏
  • 举报
回复
[Quote=引用 107 楼 eye_119_eye 的回复:]
大伙可以组团去 创新工程面试了
[/Quote]
chrome 没传好
eye_119_eye 2011-04-19
  • 打赏
  • 举报
回复
大伙可以组团去 创新工程面试了
xqqkl 2011-04-19
  • 打赏
  • 举报
回复
mark。牛B就在讨论中出现
--reply by CSDN Study Trial V1.0.1 (starts_2000)
海涛 2011-04-19
  • 打赏
  • 举报
回复
[Quote=引用 87 楼 crushor 的回复:]
哦,其实一次遍历即可

C/C++ code

int main(int argc,char argv[])
{
char str[] = " I love this game ";
int nLen = strlen(str);
int i = nLen;
while(i>=0)
{
if(' '!=str[i]……
[/Quote]

貌似你的 是 两次遍历
xxbb 2010-10-14
  • 打赏
  • 举报
回复
學習了~~~~~~~~~~~
加载更多回复(103)

64,656

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧