I am getting wrong answer for the following problem.....
#include <iostream>
#include <list>
#include <string>
#include <cctype>
#include<stdio.h>
#include<string.h>
using namespace std;
void Msort(char*a,int size);
void init(int*);
int c[256];
int main()
{
char str1[1010],str2[1010];
int i;
while(cin>>str1>>str2)
{
Msort(str1,strlen(str1));
Msort(str2,strlen(str2));
//cout<<str1<<"\n";
//cout<<str2;
for(i=0;str1[i];i++)
c[str1[i]]++;
/*for(i=0;i<256;i++)
printf("%d",c[i]);*/
for(i=0;str2[i];i++)
if(c[str2[i]]!=0) { printf("%c",str2[i]); c[str2[i]]=0;}
printf("\n");
init(c);
}
return 0;
}
void Msort(char*a,int size){
int i,j;
char temp;
for(i=0;i<size;i++){
for(j=0;j<size;j++)
{
if(a[i]<a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
void init(int*arr){
int i=0;
for(i=0;i<256;i++) arr[i]=0;
}
i there something wrong with the logic or are there in strange testcases