Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- int check_anagram(char*s){
- int i,j,c=0;
- for(i=0;i<strlen(s)/2;i++){
- for(j=strlen(s)/2;s[j]!='\0';j++){
- if(s[i]==s[j]){
- s[j]='*';
- break;
- }
- }
- }
- // printf("\n");
- // puts(s);
- for(j=strlen(s)/2;s[j]!='\0';j++)
- {
- if(s[j]!='*')
- c++;
- }
- return c;
- }
- /*int check_for_anagram(char*s1,char*s2){
- int c=0,i,j;
- for(i=0;s1[i]!='\0';i++){
- if(s1[i]!='*'){
- for(j=0;s2[j]!='\0';j++){
- if(s1[i]==s2[j]){
- s2[j]='*';
- break;
- }
- }
- }
- }
- for(i=0;s2[i]!='\0'){
- if(s2[i]!='*')
- c++;
- }
- return c;
- }*/
- int main(){
- int n,i,k=0;
- // printf("enter no of cases....");
- scanf("%d",&n);
- int a[n];
- for(i=0;i<n;i++)
- a[i]=0;
- for(i=0;i<n;i++){
- char *s;
- s=(char*)malloc(10000*sizeof(char));
- scanf("%s",s);
- if(strlen(s)%2!=0){
- a[k]=-1;
- k++;
- }
- else{
- a[k]=check_anagram(s);
- k++;
- }
- }
- for(i=0;i<n;i++){
- if(i==n-1)
- printf("%d",a[i]);
- else
- printf("%d\n",a[i]);
- }
- }
Add Comment
Please, Sign In to add comment