Anagram Function - Reapeated letters Problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 675
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 100
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: Anagram Function - Reapeated letters Problem

 
0
  #11
Aug 15th, 2009
Well, THis was my approach to the code.

  1. for (int a=0; a<str1.size();a++)
  2. {
  3. size_t val=str2.find(str1[a]);
  4. if(val==string::npos)
  5. return false;
  6. else
  7. str2.erase(val,val);
  8. }
  9. return str2.empty();
THough i dint try it out, hope it works fine.
Last edited by Sky Diploma; Aug 15th, 2009 at 9:39 am. Reason: Corrected Syntax errors. and some logical errors.,
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 675
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 100
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: Anagram Function - Reapeated letters Problem

 
1
  #12
Aug 15th, 2009
A Small change would be .....

  1.  
  2. str2.erase(val,val);
to
  1. str2.erase(val,1);

Thanks to tux4life.
Last edited by Sky Diploma; Aug 15th, 2009 at 9:58 am.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Anagram Function - Reapeated letters Problem

 
0
  #13
Aug 15th, 2009
And....Another approach (maybe not the most efficient one):
  1. bool isAnagram(string str1, string str2)
  2. {
  3. sort(str1.begin(), str1.end());
  4. sort(str2.begin(), str2.end());
  5. if(str1 == str2) return true;
  6.  
  7. return false;
  8. }
(You'll need to include the algorithm header file, you can do this by adding the following include directive to your program: #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."
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,337
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 167
firstPerson's Avatar
firstPerson firstPerson is online now Online
Nearly a Posting Virtuoso

Re: Anagram Function - Reapeated letters Problem

 
0
  #14
Aug 15th, 2009
.
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC