Anagram palindrome checking
I think you might be overcomplicating the whole thing.

How do you define a palindrome? No matter which direction you're reading it, it's the same word. As you mentioned already, this means that all occurences of characters have to be even, except for one, which might be odd. However, the string length doesn't matter for this (it's just a logical consequence):

All characters with even occurences don't matter and can be ignored. You only have to count the number of characters who've got an odd count.


With no odd count: abccba - this is a palindrome.
With one odd count: abcba - this is a palindrome as well.
With two odd counts: abcdba - this isn't a palindrome.


So the task boils down to one simple task: Count the number of odd character counts.



Some code things I've noticed:


Try to avoid using using namespace. It might bite you in the back once you've got ambigious code and accidently call (or pass) the wrong function and you're unable to find the reason for some bug.
Try to be more consistent with your whitespace characters. In some places you've put them there, in other cases you've omitted them. Overall this makes your code quite a bit harder to read (at least for me).
Don't use single-char variables (a, i, k, etc.) unless they're iterators. This isn't JavaScript. You usually don't have to optimize code size. Instead use talking variable names, even if it's just "index" or "offset".
I'd also try to use a constant value rather than calling specific members over and over again, if you don't expect them to change. In your case this would be the check inside your loop: while(i&lt;s.size()-1) { You don't know what's happening inside std::string::size(). While highly unlikely, this might actually iterate over your whole string every loop to determine the current length, making your code even more inefficient. Just ensure your compiler knows it's going to be constant:

  const std::string::size_type length = s.size();
  while(i &lt; length - 1) {
      // ...
  }





In your solution you start by sorting the whole string (which is most likely O(n²)). After this you're iterating over all elements a second time to do the actual counting (O(n)).

To me this is quite suboptimal, especially if you're able to use some memory for this.

I'd try something like the following code, which will iterate over the input string and count the occurences of every character (O(n)). In a second loop I count the number of even and odd occurences (O(1)).

#include &lt;iostream&gt;

int main(int argc, char **argv) {
    // Let's just assume argv[1] holds the string

    // This will hold all character counts, initialized to 0
    unsigned char counts[256] = {0};

    // Iterate over the string...
    for (unsigned char *pos = reinterpret_cast&lt;unsigned char *&gt;(argv[1]); *pos; ++pos)
        ++counts[*pos]; // ...and count

    // Counts for even/odd:
    // - Even -&gt; index 0
    // - Odd -&gt; index 1
    unsigned int eo[2] = {0};

    // Now iterate over all characters
    for (unsigned int i = 0; i &lt; 256; ++i)
        ++eo[counts[i] % 2];

    if (eo[1] &gt; 1) { // More than one odd count - can't be an anagram
        std::cout &lt;&lt; "No anagram can be a palindrome, since there are multiple unique characters." &lt;&lt; std::endl;
        return 0;
    }

    // At most one odd count; this can be an anagram
    std::cout &lt;&lt; "There might be an anagram that is a palindrome." &lt;&lt; std::endl;
    return 0;
}


The big advantage here in my opinion is the fact that there's no branching outside any loop construct (except that one final check).

You could however, just skip the counting of even/odd counts and use a single bool to determine whether you've got a second occurence of an odd count (which would mean that you don't have any palindrome).