-2

文字列比較関数を使用するのではなく、各文字を反復処理して C++ で等価性をテストすることにより、文字列が別の文字列に存在するかどうかを確認するにはどうすればよいですか?

string one="hello world"; // Search *in* this string
string two="wor";         // Search *for* this string
4

1 に答える 1

0

宿題みたい^^

int find(string one, string two){
    int a, b;
    for(int c = 0; c + two.length() < one.length(); c++){
        a = 0;
        b = c;
        while(a < two.length() && one[b++] == two[a++]);
        if(a == two.length())return c;
    }
    return -1;
}
于 2012-06-24T11:30:50.637 に答える