爱问知识人 爱问教育 医院库

c 错哪里?若S1 是S2的substring , return 位置 , 若不是,return -1

首页

c 错哪里?若S1 是S2的substring , return 位置 , 若不是,return -1

#include 
#include
using namespace std;

int indexof( const char *s1 , const char * s2)
{
int L1=strlen(s1) , L2=strlen(s2);
if( L1>L2)
return -1;
else if (L1>s1;
cin>>s2;
cout<<indexof(s1,s2);

system("pause");
return 0;
}

提交回答

全部答案

    2018-05-10 04:23:56
  •   int indexof( const char *s1 , const char * s2)
    {
    int L1=strlen(s1) , L2=strlen(s2);
    if( L1>L2)
    return -1;
    else if (L1<=L2)
    {
    for ( int i=0 ; i<=L2-L1 ; i ) /* 应该是等号 */
    {
    if ( s1[0]==s2[ i])
    {
    char *list = new char [ L1 1];
    for ( int j=0 ;j {
    list[j] = s2[j i];
    }
    list[L1]='';

    if ( strcmp( s1 , list)==0)
    return i 1; /* 如果位置从1开始计算,否则从0开始不改 */

    }
    }
    }
    return -1; /* 没有匹配 */
    }。
      

    z***

    2018-05-10 04:23:56

类似问题

换一换

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):