国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
基于字符串移位包含的問(wèn)題詳解

http://www.jb51.net/article/37509.htm

2013


/************************************************************************/
/* 給定兩個(gè)字符串s1和s2,要求判定s2是否能被s1做循環(huán)移位得到的字符串所包含
例如,給定s1 = AABCD, s2 = CDAA,返回true,給定s1 = ABCD, s2 = ACBD,返回false*/
/************************************************************************/
#include "stdafx.h"
#include <iostream>
using namespace std;
//窮舉法
int IfRotateContain1(char *str1, const char *str2);
//空間換取時(shí)間法
int IfRotateContain2(char *str1, const char *str2);
int _tmain(int argc, _TCHAR* argv[])
{
    char str1[] = "AABBCD";
    char str2[] = "CDAA";
    int ret1 = IfRotateContain1(str1, str2);
    int ret2 = IfRotateContain2(str1, str2);
    cout << ret1 << endl;
    cout << ret2 << endl;
    return 0;
}
int IfRotateContain1( char *str1, const char *str2 )
{
    int len = strlen(str1);
    for (int i = 0; i < len; i++)
    {
        char temchar = str1[0];
        for (int j = 0;j < len-1; j++)
        {
            str1[j] = str1[j+1];
        }
        str1[len-1] = temchar;
        if (strstr(str1, str2) )
        {
            return 1;
        }
    }
    return 0;
}
int IfRotateContain2( char *str1, const char *str2 )
{
    int len = strlen(str1);
    char *p = new char[len*2+1];
    for (int i = 0; i < len; i++)
    {
        p[i] = str1[i];
        p[i+len] = str1[i];
    }
    for (int j = 0; j < len*2; j++)
    {
        if (strstr(str1, str2))
        {
            return 1;
        }
    }
    delete [] p;
    return 0;
}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
基于英文單詞的快速HASH索引算法_小徐博客 學(xué)無(wú)止境 minix and linux
微軟面試題——反轉(zhuǎn)字符串
字符串移位包含的問(wèn)題
C語(yǔ)言面試題
一文講解C語(yǔ)言字符串
RC4算法
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服