c语言编程问题,请高手解答!!问题是这样的—— 给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行。你的程序还

1个回答

  • #include

    //转小写

    char tolower( char c)

    {

    if( c >='A'&c<='Z')

    return c-'A'+'a';

    }

    //大小写敏感

    bool findstr( char * instr, char * findstr)

    {

    char *s = instr;

    char *t ;

    while(1)

    {

    t = findstr;

    while( *s != *t *s != '')

    s++;

    if( *s == '')

    return false;

    while( *t == *s *t != '' *s !='')

    s++,t++;

    if(*t == '')

    return true;

    }

    }

    //大小写不敏感

    bool findstr_i( char * instr, char * findstr)

    {

    char *s = instr;

    char *t ;

    while(1)

    {

    t = findstr;

    while( tolower(*s) != tolower(*t) *s != '')

    s++;

    if( *s == '')

    return false;

    while( tolower(*s) == tolower(*t) *t != '' *s !='')

    s++,t++;

    if(*t == '')

    return true;

    }

    }

    //主函数

    int main()

    {

    char str[100];

    char tarstr[100];

    intcount;

    intflag;

    inti;

    scanf("%s",str);

    scanf("%d",&flag);

    scanf("%d",&count);

    for( i = 0;i< count;i++)

    {

    scanf("%s",tarstr);

    if( 1 == flag findstr( tarstr, str))

    printf("%sn",tarstr);

    if( 0 == flag findstr_i( tarstr, str))

    printf("%sn",tarstr);

    }

    ::fflush(stdin);

    getchar();

    return 0;

    }