Mail Archives: djgpp/2001/08/27/16:47:42
On Mon, Aug 27, 2001 at 01:29:08PM -0400, Ramy Elmeligy wrote:
> for( ; a < greater, equal == 0 ; a++)
> {
> input1.substr(a, b).compare(input2, c, b);
> }
This is an infinite loop. equal is always 0. Probably your intention was to
write something like :
for( ; a < greater && equal == 0 ; a++)
equal = input1.substr(a, b).compare(input2, c, b);
Anyway this is a simpler implementation:
----------------------------------------------
#include <algorithm>
#include <string>
using namespace std;
bool is_anagram(string a, string b) {
sort(a.begin(),a.end());
sort(b.begin(),b.end());
return a == b;
}
int main() {
cout << is_anagram("aba","baa") << endl;
return 0;
}
----------------------------------------------
--
Andrea Mazzoleni <am AT mediacom DOT it>
935A 2D3C 5C70 BCD6 CB0C ED89 7C19 4321 6340 3F6D
- Raw text -