码迷,mamicode.com
首页 > 其他好文 > 详细

兆芯笔试题(2015)找重复数最多的字母的数量以及位置

时间:2014-10-20 13:36:21      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:style   io   os   ar   sp   on   art   amp   bs   

例子:“aaaabcaa”,查找a则返回值为0,长度为4;

#include <iostream>

#include <stdio.h>
using namespace std;


int find_max_repeat(char *str, char ch, int *len)
{
   char *p=str;
   int num(0),start(0);
   while(*p!=‘\0‘)
   {
if(*p==ch){
 int s=(p-str),k=0;
      while(*p==ch)
 {
  ++p;
  ++k;
 }
 if(k>num){
    num=k;
         start=s;
 }
}
else
        ++p;
   }
   *len=num;
   return start;
}
int main()
{
   char str[]="abaacdeeeeesceebd";
   int i,j;
   i=find_max_repeat(str, ‘a‘, &j);
   printf("%d,%d\n",i,j);
   i=find_max_repeat(str, ‘e‘, &j);
   printf("%d,%d\n",i,j);
   return 0;
}

兆芯笔试题(2015)找重复数最多的字母的数量以及位置

标签:style   io   os   ar   sp   on   art   amp   bs   

原文地址:http://blog.csdn.net/zhuzhiqi11/article/details/40298649

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!