Guest User

Untitled

a guest
Mar 17th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. int check_anagram(char*s){
  5. int i,j,c=0;
  6. for(i=0;i<strlen(s)/2;i++){
  7. for(j=strlen(s)/2;s[j]!='\0';j++){
  8. if(s[i]==s[j]){
  9. s[j]='*';
  10. break;
  11. }
  12. }
  13. }
  14. // printf("\n");
  15. // puts(s);
  16. for(j=strlen(s)/2;s[j]!='\0';j++)
  17. {
  18. if(s[j]!='*')
  19. c++;
  20. }
  21. return c;
  22.  
  23. }
  24. /*int check_for_anagram(char*s1,char*s2){
  25. int c=0,i,j;
  26. for(i=0;s1[i]!='\0';i++){
  27. if(s1[i]!='*'){
  28. for(j=0;s2[j]!='\0';j++){
  29. if(s1[i]==s2[j]){
  30. s2[j]='*';
  31. break;
  32. }
  33. }
  34. }
  35. }
  36. for(i=0;s2[i]!='\0'){
  37. if(s2[i]!='*')
  38. c++;
  39. }
  40. return c;
  41. }*/
  42. int main(){
  43. int n,i,k=0;
  44. // printf("enter no of cases....");
  45. scanf("%d",&n);
  46. int a[n];
  47. for(i=0;i<n;i++)
  48. a[i]=0;
  49. for(i=0;i<n;i++){
  50. char *s;
  51. s=(char*)malloc(10000*sizeof(char));
  52. scanf("%s",s);
  53. if(strlen(s)%2!=0){
  54. a[k]=-1;
  55. k++;
  56. }
  57. else{
  58. a[k]=check_anagram(s);
  59. k++;
  60. }
  61. }
  62. for(i=0;i<n;i++){
  63. if(i==n-1)
  64. printf("%d",a[i]);
  65. else
  66. printf("%d\n",a[i]);
  67. }
  68. }
Add Comment
Please, Sign In to add comment