| | |
Anagram Function - Reapeated letters Problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Well, THis was my approach to the code.
THough i dint try it out, hope it works fine.
C++ Syntax (Toggle Plain Text)
for (int a=0; a<str1.size();a++) { size_t val=str2.find(str1[a]); if(val==string::npos) return false; else str2.erase(val,val); } return str2.empty();
Last edited by Sky Diploma; Aug 15th, 2009 at 9:39 am. Reason: Corrected Syntax errors. and some logical errors.,
A Small change would be .....
to
Thanks to tux4life.
C++ Syntax (Toggle Plain Text)
str2.erase(val,val);
C++ Syntax (Toggle Plain Text)
str2.erase(val,1);
Thanks to tux4life.
Last edited by Sky Diploma; Aug 15th, 2009 at 9:58 am.
And....Another approach (maybe not the most efficient one):
(You'll need to include the algorithm header file, you can do this by adding the following include directive to your program:
C++ Syntax (Toggle Plain Text)
bool isAnagram(string str1, string str2) { sort(str1.begin(), str1.end()); sort(str2.begin(), str2.end()); if(str1 == str2) return true; return false; }
#include <algorithm> ) Last edited by tux4life; Aug 15th, 2009 at 10:22 am. Reason: add info about include
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
.
Last edited by firstPerson; Aug 15th, 2009 at 11:44 am.
1) What word becomes shorter if you add a letter to it?
[ Solved by : niek_e, Paul Thompson, SgtMe, murtan, xavier666, jonsca]
2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
[*solved by : murtan, xavier666]
3) What is the 123456789th prime numer?![]() |
Similar Threads
- Sony Vaio Fn key problem (USB Devices and other Peripherals)
- tolower function does not work on certain letters (C++)
- problem with calling a function (C++)
- problem in sqlcxt() function in pro*c (C++)
- operator/function for a list of letters (Python)
- Big Problem, Generic Error (VB.NET)
- Create Function that prints letters, words and sentences (C++)
Other Threads in the C++ Forum
- Previous Thread: inheritence problem with more explanation
- Next Thread: write to file program
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






