由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 问一道C++面试题
相关主题
对coding初学者,我的建议是Software Developer position at TX
求教有没有好的查Java memory leak的工具? (转载)请问物理专业PhD转码工应该学那种语言?
java code在不同机器上内存消耗差异很大怎么回事?烂校毕业找工作不容易啊
Java系统中GC频繁启动是什么原因?free finite element analysis code?
Workflow design请教工科算法编程较多,想系统学点计算机课程。选computer theory有用吗?
社会就是个API框架,社会经常被革命。由此推出答superband : 找Quant 的准备和自己的心态
string matching 需要看KMP 还有其他需要看的吗?[合集] 答superband : 找Quant 的准备和自己的心态
Software Developer position at TX请问学数学的适合申请哪些金融工作呀?
相关话题的讨论汇总
话题: char话题: string话题: characters话题: int话题: output
进入Programming版参与讨论
1 (共1页)
t*****n
发帖数: 25
1
Program a fast and simple solution to the following problem without using
any
regular expression or pattern matching utilities. Given a non-finite stream
of
characters, output an "A" if the characters "xxx" are found in exactly that
sequence. If the characters "xMx" are found instead, output a "B". Do not
re-
process characters so as to output both an “A” and a “B” when processing
the
same input. For example:
1. The following input xxMxMxxxMxxx would produce the following output: BAA
2. The
r*********r
发帖数: 3195
2
#include
#include
using std::cout;
using std::endl;
using std::string;
string process(const string& s)
{
string r;
for(int i=0; i if( s.substr(i,3) == "xxx" ) {
i += 2;
r += 'A';
}
else if( s.substr(i,3) == "xMx") {
i += 2;
r += 'B';
}
}
return r;
}
int main()
{
cout << process("xxMxMxxxMxxx") << endl
<< process("xxxMxMxxxxMMxMxMx") << endl;
return 0;
}
s*******n
发帖数: 688
3
DNA sequencing?

stream
that
not
processing

【在 t*****n 的大作中提到】
: Program a fast and simple solution to the following problem without using
: any
: regular expression or pattern matching utilities. Given a non-finite stream
: of
: characters, output an "A" if the characters "xxx" are found in exactly that
: sequence. If the characters "xMx" are found instead, output a "B". Do not
: re-
: process characters so as to output both an “A” and a “B” when processing
: the
: same input. For example:

t*****n
发帖数: 25
4
Good solution!

【在 r*********r 的大作中提到】
: #include
: #include
: using std::cout;
: using std::endl;
: using std::string;
: string process(const string& s)
: {
: string r;
: for(int i=0; i: if( s.substr(i,3) == "xxx" ) {

x*******j
发帖数: 17
5
我的答案:用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
q*c
发帖数: 9453
6
有重复。 不等的时候, 已经比较了 2-3 个字符, 但是只
往前移动一个。
应该用状态机,就最高效率。

【在 r*********r 的大作中提到】
: #include
: #include
: using std::cout;
: using std::endl;
: using std::string;
: string process(const string& s)
: {
: string r;
: for(int i=0; i: if( s.substr(i,3) == "xxx" ) {

1 (共1页)
进入Programming版参与讨论
相关主题
请问学数学的适合申请哪些金融工作呀?Workflow design请教
JPM interview questions社会就是个API框架,社会经常被革命。由此推出
请教:如果想工科PhD转行做Quant该学什么样的课程?string matching 需要看KMP 还有其他需要看的吗?
***CAN I try this kind of job? Thanks!Software Developer position at TX
对coding初学者,我的建议是Software Developer position at TX
求教有没有好的查Java memory leak的工具? (转载)请问物理专业PhD转码工应该学那种语言?
java code在不同机器上内存消耗差异很大怎么回事?烂校毕业找工作不容易啊
Java系统中GC频繁启动是什么原因?free finite element analysis code?
相关话题的讨论汇总
话题: char话题: string话题: characters话题: int话题: output