String compression

This is my code but still two cases are failed ut according to me it should not fail. I think the test cases 2,3 are wrong because i unlock them and by mistake and when i saw the output it should not what the question.
Testcase 2 (input according to codingblocks) :
aaaaaaaaaaaaaaagggxsxssyyyyyoooooooooolllllwwqwdeddddddddkjjjoooooooooooooooooooo
Output for this testcase according to codingblocks is : a15g3x1s1x1s2y5o10l5w2q1w1d1e1d8k1j3o20

Isn’t it wrong???
PLease check my code my ans is a15g3x2s3y5o30l5w3q1d9e1k1j3

#include
using namespace std;
int main() {
char str[1000];
int freq[256]={0};
cin>>str;

for(int x=0;str[x]!='\0';x++){
    ++freq[str[x]];
}
 for(int x=0;str[x]!='\0';x++){
    if(freq[str[x]]>0){
        cout<<str[x]<<freq[str[x]];
        freq[str[x]]=0;
        }
    }

return 0;}