百度笔试题

来源:互联网 发布:人工智能能否取代人类 编辑:程序博客网 时间:2024/06/06 14:02

int maxContinuNum(const char *inputstr,char * outputstr)
{
 bool flag=false;
 char *cur=NULL;
 char *p=(char *)inputstr;
 int len=0;
 int maxLen=0;
 while(*p)
 {
  if((*p>='0')&&(*p<='9')&&!flag)
  {
   flag=true;
   cur=p;
  }
  if(*p>='0'&&*p<='9')
   len++;
  else
  {
   flag=false;
   len=0;
  }
  if(len>maxLen)
  {
   maxLen=len;
   outputstr=cur;
  }
  p++;
 }
 //cout<<maxLen<<endl;
 //cout<<*outputstr<<endl;
 return maxLen;
}

 

 

1、公司技术部接到一个任务,需要使用a-z0-9组成3位的字符密码,现请你设计一个算法,将可能的密码组合全部打印出来。(10分)

#include<stdio.h>
#include<stdlib.h>

void main()
{
 //cout<<midnum(a,b,0,1,0,1)<<endl;
 FILE *fp=fopen("test.txt","w");
 for(int i=0;i<36;i++)
  for(int j=0;j<36;j++)
  {
   for(int k=0;k<36;k++)
   {
    if(i>=0&&i<=9)
     fprintf(fp,"%d",i);
    else
     fprintf(fp,"%c",i+87);
    if(j>=0&&j<=9)
     fprintf(fp,"%d",j);
    else
     fprintf(fp,"%c",j+87);
    if(k>=0&&k<=9)
     fprintf(fp,"%d ",k);
    else
     fprintf(fp,"%c ",k+87);
     
   }
   fprintf(fp,"\n");
  }
 fclose(fp);  
}

 

2、请实现字符串反转函数。


void myreverse(char *str)
{
 char *p,*q;
 p=str;
 while(*p)
  q=p++;
 p=str;
 while(p<q)
 {
  char t=*p;
  *p++=*q;
  *q--=t;
 }
}

void main()
{
 char str[]="yanzhengfei";
 cout<<str<<endl;
 myreverse(str);
 cout<<str<<endl;
}