华为笔试只会的第一道题...第二道不会...
时间:2010-08-23 来源:marrywindy
今下午华为上机笔试,第一年上机笔试,两道题。
我非常不满下午笔试的情形,电脑上只有VC6.0,我平常用习惯了VS,很不习惯。
还有一大系列乱七八糟的下载题目,提交,很乱...
只会第一道题,第二道不会。
第一道:删除子串,只要是原串中有相同的子串就删掉,不管有多少个。

#include "stdio.h"
#include "stdlib.h"
#include "assert.h"
#include "string.h"
int delete_sub_str(const char* str,const char* sub_str,char* result)
{
assert(str!=NULL && sub_str!=NULL);
const char* p;
const char* q;
int length=strlen(sub_str);
for (p=str;*p!='\0';p++)
{
q=sub_str;
if (*p!=*q)
{
*result=*p;
result++;
}
else
{
const char* temp;
temp=p;
int count=0;
do
{
count++;
temp++;
q++;
} while (*temp==*q);
if (count<length)
{
const char* t=p;
for (int i=0;i<count;i++,p++)
{
*result=*p;
result++;
}
p=p-1;
}
else
{
p=temp-1;
}
}
}
if (NULL!=result)
{
return 1;
}
else
return -1;
}
int main()
{
char s[100]={'\0'};
int flag=delete_sub_str("zhaoshshhihiihihshijiezhaoshijieabcdshizaoshhssssshishishshshhihihi","shi",s);
if (flag==1)
{
printf("%s\n",s);
}
return 0;
}
反正上机的时候,没有在自己电脑写的爽...
还给了啥鸟模板...靠....
一塌糊涂...
挂了....
相关阅读 更多 +