0 like 0 dislike
19.2k views

Write a function that tests whether two words or phrases are anagrams (permutations of the same letters):

寫一個判斷兩個單詞或詞組是不是符合易位構詞的函數。

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
   /*INSERT YOUR CODE HERE*/


   /*END OF YOUR CODE*/
   //The function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int main(void)
{
   char A[100],B[100];
   /*INSERT YOUR CODE HERE*/


   /*END OF YOUR CODE*/
   if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
   else printf("Two words or phrases are not anagrams");

   return 0;
}

Example input:

smartest
mattress

Example output:

Two words or phrases are anagrams

Example input:

dumbest
stumble

Example output:

Two words or phrases are not anagrams

Remember: You may correct the cases, but your code always be revised! 

[Exercise] Coding (C) - asked in Chapter 9: Functions
ID: 39986 - Available when: Unlimited - Due to: Unlimited
| 19.2k views
0 0
STRUPES!

79 Answers

0 like 0 dislike
Hidden content!
#include * ***** * ** * *
#include ** ** ** ** **
#include *** * ****
int * ** * *** A[],char B[])
{
*** * *** ***** ** YOUR CODE HERE*/
* *** *** * * ** * * ** * ** *
**** * * **** ** * * ** ***** ** * **** * * ** **
* *** ** * * * * * ** *
* * *** * ** ***** *** * * ** *** * **** *** * *
*** ** ** **** * * * ********* * * * * *** *** ** ** * *
*** *** * ** **
* * * *** * *** **** * (A[i] || B[i])
************* * * * * * *** 0;

** * ** *** * * ****** (i = 0; i < 256; i++)
* **** * * ** ** * ** * ** ** *** ** * * *** ** *
*** * ** * * * ** ** * *** ** * **** ** * * **** * * ***** * 0;
*** ***** * ***** *** *** ** 1;

* *** *** * * OF YOUR CODE*/
** * **** **** * * * function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int ** **
{
**** ** * ** * * * ***
** * * * ** * * * YOUR CODE HERE*/
** *** * * * ****** * * * ** * **** * **** * ** *
* * * * * * ** ** * * * * ** * *** * *

*** * * * * * OF YOUR CODE*/
* **** **** ** * ** ** *** *** * words or phrases are * *** ** * *
*** * * *** * * * *** ** words or phrases are not ** * **** *** *

*** * * ** 0;
}
answered by (-196 points)
0 0
prog.c: In function 'main':
prog.c:29:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat=]
     scanf("%s",&A);
             ^
prog.c:30:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat=]
     scanf("%s",&B);
             ^
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
* * * *** ***** **** ** i[26],j[26],a,b,cI,cJ,z=0;
** ****** * ** *** * *** **
   {
*** * * ***** * **** ** * * **** * * ***
* ** * * * * * ** * * ** * ** * ** *
   }
*** * *** **** * * *
****** *** * * ** * *
** ****** * * * * ***** * **
** ** *** ***
* * * * * *** * * * ** * ** * **** * ** *** *
***** ** * *** ** * ** *** ** ***
*** * * * ** * **** * * * * **** * ** * * **** * * *** * * ** *** ** * * * ***
* *** * ** *** ** * ** * *** ** **** * * * * * * *** **
* ** * *** * * * ** * ** **** * ** * * ** ** ** * *** * *** *** * * *** * * *
****** * ** * ***** * * *** * *** * * * * ** *** ** **
** * * ******** **** *** * ** * * ** **
** **** ** * * * ** * *** * * ** *** * ** *
   }
* * ** ** * ** *** * ** * *
   {
* * * * * * * **** **** ** * * *** * ** *
* * * ** ** * *** * * ***
****** * * * *** **** **** * ** ** **** ** ***** ** * ** * * *** ** ***
********* * ** *** * * ** *** * ** * *** * * ** *
********* * ** ***** ** * ** * * *** * * * *** ** * **** ** *** * * ** * * * * ** *
* ** ** * * ** ****** *** * * *** **** *** * * ** * *
** ** ***** * ** * ** ******** *** * * * * **
** * ******** ** * *********** ** ** * ***
   }
* * ** ****** ** * * * *
   {
* *** * * ** *** *** ****** ** *** **** ** * *
** ** * * *** * ***** *** * **** * * **
* ** ***** * ** * * * **** ** ** * *** ******* *** ** *
* * **** * * * *** **** ** ** ** **
   }
** ** * ***** * **
   {
** * * * **** ** ** * * *** * * ****** * 1;
***** ****** *** **
**** * * * * * *
** * * ***
* * * *** ** ** ** * ** * * * ** * * 0;
** ********* *
* **** **** * ** *** function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int main(void)
{
*** *** * * * **** *** A[100],B[100];
**** * ** ** ** * * YOUR CODE HERE*/
*** **** * * * * *** * i;
**** ** * *** * *** *****
   {
**** * * ** ** * ** * **** *** **** ** **
* ** **** * * **** * ** *** ** ** ** ** * * **
* * * * *
** * * *** ** ** ** ** **
***** ** *** * ***** **** **
* **** **** *** **** OF YOUR CODE*/
* ** *** * *** (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
* * ****** * **** printf("Two words or phrases are not anagrams");

* * * * 0;
}
answered by (-255 points)
0 0
prog.c: In function 'is_anagrams':
prog.c:12:14: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
    cI=strlen(i);
              ^
In file included from prog.c:2:0:
/usr/include/string.h:394:15: note: expected 'const char *' but argument is of type 'int *'
 extern size_t strlen (const char *__s)
               ^~~~~~
prog.c:13:14: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
    cJ=strlen(j);
              ^
In file included from prog.c:2:0:
/usr/include/string.h:394:15: note: expected 'const char *' but argument is of type 'int *'
 extern size_t strlen (const char *__s)
               ^~~~~~
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include ** **
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
* * ** ** * ** * ** * *** ** ** YOUR CODE HERE*/
** ** ** * ** ** ** * * * * * *** *** OF YOUR CODE*/
** *** *** ** *** ** * ***** * ** **** *** **
* * * * *** * * ** *** * * * * *** * * ** * * *** * * **** *
* * ** * * * *** **** ** * * * * ****** *** * ** ** * *** *** ** * * * **** ***
** * * ** * * *** ** ** ** * * *** *
* *** *** *** * **** * **
** *** * *** ** * ** * ** * ***** **
* ** **** ** ** * * *** * **** * * * ** * * ** * * **** **** **
** * ** * *** * * * * ******* *** ** * * * ** *** * * ** * ** ** ** ***** *** ** ***
**** ****** **** ** *** *** *** ** ** * * * ** * ** * * *** * **** * **** ** ** * * ******* ** **
** *** * * * *** * ** * * ** *** * * *
* * ** ** * *** * * * **
*** *** ** ***** * * *** ****
* *** ******** ******** ** * ***** ** ** * *
* * ** * ***** * * *** * **** *** * ** ** ***** ** *** ** ** ** ** ** 0;
* ** ** ** ***** *
** ******* * *** ** * * *** 1;
* * * ***** ** * * ** function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int main(void)
{
****** * **** **** ** A[100],B[100];
** *** * * * ** * * * ** ** *
* ***** *** **** * * *********
** * * * ** * * * (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
** ** ** *** printf("Two words or phrases are not anagrams");

*** ** * * ** ** 0;
}
answered by (-498 points)
edited by
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
-----------Re-judge-----------
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
   /*INSERT YOUR CODE HERE*/
   int letter[26]={0};
   int Letter[26]={0};
   int j,n, anagram = 1;
* ** * ** * *** *** **** ***
** *** * *** * *** *
* *** * * ** * ** ** * **** * ** * ** * * ** * * * ** * * * * ****
** ** *** *** * * * ** * ** ** * * * ** ** * ** ** * ** * *** **** * ** * *** ** *
* * * ****** ** * ** * ** *** * * ** *** * * *** *** ** * ** * * * * * ***** * ** * * * *** * || A[n]==97+j)
* * ** * * *** ** ** **** ** * * * **** * * ***** ** * *** * * * * * **** * ** ** ** ** ** **** * *** * *
* * ** * ** ** ** ** * * * * * ******* * ** **** * ***** ** *** ***** * * ** * * * * ****** ** * * *** *** ** **** * ***** * * * *** * * * * * * ** *
* * ** ** ****** * ** * ** ** * ** * ** * * * ** * ** *** * *** *** * **** * ***** ******* * * * ** ***** *
****** * ** * **** * ***** ****** *** ***** ***** *** ** ** **** * * **

** **** * ** * **** * ******
* ** ** ** * ** * ** ** ** * ** ** *
* ** *** ***** ** * **
* ***** * * * **** *** *** * * ** * * **** ** * *** * **** * * ** * **** *
* ** * * * ** * ** ** **** * ****** * *** ** * * ** ** * * * * ** * * *
* * ** * *** ** * *** * ** ** * * * * * * ** ***** * ** ** ** *** * ************ *** ** *** ** * * || B[n]==97+j)
*** ** ** ** ** * * * * * *** *** **** ** * * * ** * ** * * *** ****** ** ** * ** * * * * ** * * ** * **** **** ** *
* * * **** *** ** * * ** * ** * **** * ** * *** * * ** * * **** * * * * ** * ** * * ** **** *** * * * *** ** ** ** *** *** * ** * * *** * ***
* * * * *** **** ** ** ** ** ***** *** * ***** *** * * * ** * * * * ****** * * * * * * * ** * * ** ** * ** * * * **** * *
* * * ***** ** * **** * ** ** * ** ** * * * * * ***** ** **** * * ** ** * *

** *** **** * ** **
* * *** ** * *** * * * *** ***
** * * * * * **** ******* ** * ** ** * * *
* *** * *** ** * * * ** * * * * ** ***** * * ** * ** * ** * * ** ** ** ** ** * **** ** * **
*** *** * ** * ** * * *** ** * * ** * *** *** *** * ** ** * **** ** *** * * ** ******** ** * * * **** anagram = 0 ;
** *** * * ******** **** * ** * * * ** ** ** ** * * ** * ** **** *** * * * * * * * * ** * **** **** * *
* ******* ** * ** *** ** ** *** * ** * * *** * * * * * * **** ***** *** ** * * * * *** * **** ** ** * * ** *****


* *** * *** * * * * * ** * * *
** * ** * *** * * ******* ** ** * * ** == 1)return 1;
* * * *** ** ******* *** * * **** * return 0;


   /*END OF YOUR CODE*/
   //The function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int main(void)
{
   char A[100],B[100];
   /*INSERT YOUR CODE HERE*/
* * * *** ** * * * *** ****
*** * ** ** ** ** **** **


   /*END OF YOUR CODE*/
   if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
   else printf("Two words or phrases are not anagrams");

   return 0;
}
answered by (-301 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
* * ** * ** * * * * YOUR CODE HERE*/
   int letter[26]={0};
   int Letter[26]={0};
   int j,n, anagram = 1;
* * * * **** * * *** * * * ** *
* ** **** ** * * ** ***
** * ** * * * ** **** * ** * * * ** *** ** ** * ** ***** ** * ****
** * * * ** * * **** * ***** *** * * ******** ** ** * * *** ** ***** **** * ***
* * *** *** * * * ***** *** * **** ** * ** * * * ** * ** ***** ** ** * **** *** ** * **** * * * ** * ** *** || A[n]==97+j)
*** * * ** * * * * * * *** ** ** *** ** * * * * **** * ** * * * **** * ** ** ***** * *** * ***** ** * * ** * * *
* * ****** *** * * ******* **** * ** *** *** * *** * * **** ** **** * * *** ***** ***** ** ****** **** ** * ** * * ***** *** *** * ****** * * *** * *
*** ** * * *********** ** * ** * ***** * * ** * *** * * ** * * * * **** *** * **** * * * ** *** ** * *** * * *** * * * * **
* *** * * *** * * * * * * *** * * * * ** ** * ** ***** * * * **** ** ****** * **

* *** * ** * *** * *
**** * * *** * ** ** ** * * ***
** * *** *
* * ** *** * ** * * * ******** * * ******* ** ******** * ** ** * * ** * ****
* * *** * **** * * * * *** ** ** ** *** ** ** * * ** *** ** **** ** ** ** ** ** ***
* * * ** **** ** * *** ** * * * * * ** **** * * * * ** ** * * * * * * * * ** * ***** * *** *** || B[n]==97+j)
* * * * *** * ******** * ***** ******** * * ******* ** ** ** * *** * * *** ** * * **** *** * * ** ** * ********
* *** ** *** ***** **** ** * * * * *** * ***** * * ** **** * * * **** ** ** *** * ***** ** * ** * * * * * * * * *** * ** ** * ** ** *
** ** * * * ** * ** ** * *** *** ***** ** ** * * * * * * ** ***** * * ** ** *** * *** **** * **** *** * *
*** * ** *** ** * * ***** **** * * ** * * ** ******* * ***** * * *** ** * ** * * * * **

* **** ****** * *** *
* ** * * ** **** ***** ** * **** * *
** **** *** ****** ** *** * ** ** * * * *
* ** **** * ** * * * *** ** * * * * ** * ********* ** ** *** * * * * ** * *** * ** ***** * ** * anagram = 0 ;
** * ** *** * ** ** ** * * * * *** * * ** ** *** **** ** * * ** * *** *****

** * ***** ** *** * * ***** *** * ** * *
* * * ** *** * *** *** ** ** ** ** * == 1)return 1;
* ** ** * ** * **** **** return 0;


   /*END OF YOUR CODE*/
   //The function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int main(void)
{
   char A[100],B[100];
*** *** *** * **** * YOUR CODE HERE*/
* * * ****** ** * **
* * ****** *** ** * ** * **** **


   /*END OF YOUR CODE*/
   if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
   else printf("Two words or phrases are not anagrams");

   return 0;
}
answered by (-301 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Correct output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
    int i,j,c[26]={},d[26]={};
    char ** * * **** *** * * ** * ** *** * * ** * * ** * * ***** ***
***** ***** ** **** ** * * * *** **** ** *** ** ** * * * * * **** * * ********** * * ** *** * ***
* *** * *** * ** *** ** *** * * *
* ** * **** * ** * * * * * **** * ** * ******** * * **
* * ** * * * *** * **** ** *** * ** * * *** ** * * ** * ** || b[i]==A[j]){
*** * *** *** * ** * * *** * * **** ** *** * ****** * *** *** ** * *
*** ** * *** ********* ** ** * * * ** ***** ** * *
** ** * * *** **** *** * * * * ** *** * * * * * *** * ***** ** * * * ** || b[i]==B[j]){
* * * ** ** * * ** *** *** *** ** ** * ** ** **** ** *** * * *** * * ** * ** * * ** *
*** ** **** *** *** * * * ** * * ****** * * *** *** *** ** * * * **

* * * **** * * *** * * * ** *** *** * *** *
    }
** *** ****** * * *** * *** *** ***
* * * ** * * * ** ** *** * ** *** * * ** ***** **
* *** ** * * * *** ******* *** * **** * * **** * * * * ** * *** 0;
    }
*** ** * *** ***** *** *** 1;
*** * * * ** * **** ** ** *
* ** ** ** ** * * *** **** *** **
*** * * * *** * * * * * *** *** *** * * * * **
* **** ** * * * ***** ******* * ** * **** **** * * **** ** **** * *
* ** ** ** * * * **** * ** * * * ** * ** * ** ** *** *** ****** **** * * * *
****** ** * * ** * * ** * *** * * ** * * * * * *** *** ** * * * * * * *
*** *** **** * ** ** ** ** * * * ** * ******* **** * * *** * * *
* * **** **** * * * *** * * * * * ** *
    }
** * ** * *** * * * * * ***** *** %d",l,sum);
** ** * * * * * ** ** * ** * ** *
*** * ** ** * * ** * *** * * *** * * **** * 1;
******* * ** ** **** **
* * * ** * * * *** *** *** * * * ** * * 0;*/
}

int main(void)
{
    char A[100]={},B[100]={};
** * **** ** *** ** * ***
* **** ** * ** * **** ** ***
    if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
* ** * ** *** * **** printf("Two words or phrases are not anagrams");

* * * ** ** ** 0;
}
answered by (54 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
    int i,j,c[26],d[26];
    char * * *** *** *** ** * * ** ** **** * ** * ** * * *** **
**** ****** ** **** * ** ** * * ** ** * * * ***** ****** *** *** ** * * **
* *** ** * ** * **** ***** ** ** ** * *
** *** * ** * ** * ** **** * ** * * ** * * ** * * *
* ** ** * ** * * * * ** **** * *** * **** * * ** *** ** * || b[i]==A[j]){
*** ** * *** * * * ** ** ** **** ***** * ** * *** * ** ** * * * * * ** **
* ***** ** *** * * * ** * * * ***** ** *** * *** * **** ** * * **
* *** ** *** *** * * **** *** * *** *** ** * * * **** ** || b[i]==B[j]){
** * * *** * * * ** * * ** * * ****** *** * *** * * * ****** * * ****** ** * ** ** ** ** *
*** **** * * ****** * * * * * ** *** * *** * * ** * ***

* * * * * ** * ** * ** * * * * * ** * ******* *
    }
* *** * *** ** * **** * * * *
** ** * **** * * * * * * * * * * **** * * * **
* ** ** * *** * ** ** * * *** * * * * ** ** ** * ** **** **** * * 0;
    }
* *** **** *** *** * * * * 1;
* **** * * * *** ** **** *** *
* ** **** *** * ** * * ** * ***
*** * ***** ** * ***** ** ******* * ** **** ** ***
* ** ** ** * *** ***** * ** * **** * * ** * * *** ** * * **** ***
* * ** * ** * * * * * ***** * * ** ** * ** **** * * *** * * ** * * ******* *
* * * ****** ******** * ** ** * ** * * * ****** ** ** * * * * * * ** * * * * * *** ** *** * ** *** *
**** * * ** * * *** * ****** ** * * * * ** *** *** * ** * * * * *
* * ** * *** *** * * * ** ** *** *****
    }
* * *** ** ******* * ******* * %d",l,sum);
**** * ** *** * * ** * ****
** * * ***** *** ****** * * ** * ** * ****** ** * * 1;
*** ** *** ******
* * ** ** * * ** * * *** ** * * * ** * ** * 0;*/
}

int main(void)
{
    char A[100]={},B[100]={};
** ** *** * *** * * ***
** * * *** ** ***** * ***
    if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
* ** **** * ** * *** printf("Two words or phrases are not anagrams");

***** *** ** ** *** *** *** 0;
}
answered by (54 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
    int i,j,c[26],d[26];
    char * ** * * * ** ** * ** ** ** ******* ** * *** * * * ***
** * ** **** * *** * * * ***** * * * * *** * *** **** ** *** ** * * * ** **** ** ** *
* * * * * *** ** ** * * * *** **
* * * ** **** * ******* ** * * ** * ** * ** * * ** * * *
* * **** * * * * * * * * * **** * * ** * * * * * ** * ** * * * * || b[i]==A[j]){
****** * *** *** * ** * * ** *** ***** * * ** * ** ** * * *** * * **** * * ** *** **
**** * ** ***** * *** ** * *** * *** ** * ** * * **** ** ***
** * ** ** ****** ** ******* ** *** * ****** * ** ** ***** ** ****** * * * || b[i]==B[j]){
* ** * * * * ** * *** ** **** * * ** * **** ***** * *** * * * ** * *** *
** * * * *** **** ** ****** * * * ***** * *** * * * **** **
** ** ** ** ** * *** ** * * * * * ** * * ****** * ** *** ** * * ****** * *****
** * *** ** * * * * *** **** * * * * *****
    }
* * ** *** ***** ** * *** *
* * ** ** * **** **** * *** **** *******
* * ***** * * * * *** ** *** * ** * ** ****** ** * ** *** ** * 0;
    }
** * * * * ** *** ****** 1;
** * ** * * * * ** * **
** * ** ** ** * * *** *
** ** **** * * ** ******* *** * ** ** *** *** *
**** ** * ** * * ** ** ** * ** ** ** **** * * ** * * **** * ** ** ** * * **
* *** * ** ** * * * * ******** *** * ******** * ** * * **** *** ** *** * * **** * ** **
***** ***** * ** ** * ** ** * * *** *** * * ** * * ** * ** * ** * * *** * **** ** ** **
****** * * * ** ** * ** ** * ** ** ** * * * ** ***** **** *
*** **** * *** **** *** * * * ** * ** **
    }
* *** * **** * * * ** * * %d",l,sum);
* ** * ***** ** ***** * *
* * **** * * *** *** ** * * * ** ** ** 1;
    else
* * *** **** * * * * * **** * ** * ** ** ** 0;*/
}

int main(void)
{
* **** * * * * * * ** * A[100]={},B[100]={};
* ** * *** ** ** ** * *** ** * * *** **
*** * ** **** *** *** ** ** ***
    if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
    else printf("Two words or phrases are not anagrams");

** * ****** * ** ***** * 0;
}
answered by (54 points)
0 0
prog.c: In function 'is_anagrams':
prog.c:8:5: error: expected ',' or ';' before 'char'
     char b[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','o','r','s','t','u','v','w','x','y','z'}
     ^~~~
prog.c:11:30: error: 'b' undeclared (first use in this function)
             if(a[i]==A[j] || b[i]==A[j]){
                              ^
prog.c:11:30: note: each undeclared identifier is reported only once for each function it appears in
prog.c:15:18: error: expected ';' before '{' token
                 d{i}++;
                  ^
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
* * * ** * ** YOUR CODE HERE*/
   int letter[26]={0};
   int Letter[26]={0};
   int j,n;
* * * * *** ** * ** ** *** * * * *
** * ***** ** * ** * * *
** * * * ** * ** ** * * * * * * * ** * * ** **** **** * ******* * *
* * * * ** * * * * *** ** ****** * ***** * *** * * * *** **** * * * **** *** ** * * **
** **** ** * ** * * * ** ** *** ** ** * ***** * ** **** ** * ** * * ****** ** ** * * * ** || A[n]==97+j)
* * * ***** ** ** * ** * * ** * * * * **** * * *** * ****** * * * * * * ** ** ** **** **** ** * *** * **** ** **** ** **** ******** **
** * **** ** * * * ** ** * * * * * * *** * *** ** * ** **** * ** * ** * * ***** *** ** * * *** * *** *** ** ** * *** *** * **** * * ***** * ** *** * * ** * ** * **
** ** *** ** * ****** ** * * ** ** * *** **** * ** **** * * * ** *** * * *** * ** * **** * * **** * ** **** ** * * * ** ***
* ** ***** * * * ** ** * ** * ** ** * *** *** * *** * ** **** * * ** * **** *** *

* * ** * * * ** * *
* * * ** * * **** * ******* ** * *
** * ****** * *
* * * ** **** *** * ** ***** * * * ** ***** * * ** * * * * * * ** * ** ** **
* ** * * * * ***** * * ** ** * ** ** **** * * *** * ** * ** * * * * * * ** *
** *** * * ***** * * ** * * ** ** * * *** * ** ** * ** *** *** * * ** * ** * **** * * *** * * || B[n]==97+j)
** *** * ** *** *** * ** ** ** ** * * * ** ***** **** * ** ** ** * * ** * ** **** *** * *** * * *** *** * * * ***
* * * * * ** *** ** ** ** * ** * * ** * * ** * ** * ** **** * * ** * *** * ** ** * ***** * * * * ** *** ** *** ** *** ***** * ** * * ***** **
* *** * ** ** * **** * * * ** **** **** * ***** ** * ** ** * * * ** * * * ** ** **** * * ****** * *** ** * ******* ***** *** * * **
*** ******* ******** * ***** * * * * ** ** ** * ****** * * ** ** ** **** **** * *

** ** * *** * ** **
******* * * ** ** * ** ** * *** * * **
** ** ** * * *** **** ** **** * * * ** * ** * **
* *** * * * ** *** * *** *** * * * *** * ** ******* * *** ** *** ****** ** ******* * * ** * * * return 1;
* ** * **** ** * ** * * ** *********** * ** * * *** **** ********** * **** ***** ** * * return 0;

* ** *** *** ** * ** *** * *** * ** * ** **



   /*END OF YOUR CODE*/
   //The function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int main(void)
{
   char A[100],B[100];
* * * ** * * * * YOUR CODE HERE*/
** ** * * * * * *** ***
* ** *** ** * * **


   /*END OF YOUR CODE*/
   if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
   else printf("Two words or phrases are not anagrams");

*** * * * * * ** 0;
}
answered by (-301 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Correct output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
    int i,j,l,sum=0,a[26],b[26];
    for(i=0;i<1000;i++){
        switch(A[i]){
******* ***** ** * ** * * * *** *** * * * *** ** ** * * *** * * 'A': case 'a':     a[0]++;
* ***** * * * * *** * *** *** ***** ***** * * *** ** * * * ***** ***** ** *** ******* * ** ** ** ** * * * * ** **** ** *** * * * **** * *** ** **** * **** ** * ** * * * * * * * * * *** * ***** *
** ** ** * * * ** *** * ** * *** * * ** * * * ** * *** 'B': case 'b':     a[1]++;
* **** * **** *** ** **** * * * ** ** ** * * **** * ** * ** *** * ****** * * * ** *** *** * *** ** ** * **** ** *** ** * * ** * * ***** * * ** ** **** * * * * * * * * ** *
* * ** ** * *** * * *** ** * * ** * * ** * * * ** * ** ****** * ** ** ** * 'C': case 'c':     a[2]++;
* * *** * * * ** * * * ** ** *** * * ***** * ** ** * ** ** * ******* * * ** * * ********** ** * * * ** *** * * * ** * * ** **** *** ** * * ** ** *** * * ******* * ** * * ** *** * *
**** * ** * * * ** * * * * ***** * * ** **** ** ** ** ** * * ** 'D': case 'd':     a[3]++;
* * * ** * * **** * ** * * *** * ** * * * ** ** ** * ***** ** * *** * ** *** ****** ** * * *** * ** ** ** ** * * ** ** *** *** ** ** ** * * *** ** ** * ** **** * *** ***
** *** *** * * ** ** * *** ** * * *** *** *** ** ** *** * * **** 'E': case 'e':     a[4]++;
*** * **** * ****** ** **** * * * *** *** * *** * *** ***** * * *** ** * *** *** *** ** * * * ** * ** * * * * ** ******* ** ** ** * * * * *** * * ** * * * *** **** ******* * * ** * * * * ***
* ** * ** ** ******* * ** *** ** **** ** ** * * ** * ** * ***** ****** *** 'F': case 'f':     a[5]++;
* * ** *** * * * ** ****** * ********* ** * * * * * ** * * ** * *** * ** *** * * * ** * *** ** * * **** * * **** * ** * * * * ***** ** * * ******* * ** *** *** ** ** ** ** * * * **
**** ** ** ***** ****** ** ** * ** * *** *** * * * ** * * * **** **** **** 'G': case 'g':     a[6]++;
* ***** * **** * ** * *** * ** ***** * * * * * *** ***** ** ** * ***** * **** *** * * * ** ** *** ** ** * * ** ** * ** **** ** ** * * * ** * * ** * ** * * * *** ******* * * * ** * * * *
            case 'H': case 'h':     a[7]++;
** *** * **** * *** *** ** * *** **** * **** ** * ** *** **** ** * **** ** ** * * *** * *** *** ***** *** ***** ***** * ** ** ** ***** ** ** * * * * * **** * * *** * * ** * * ** ** * * * * **
** * * *** ** * ** * ** ** ** *** *** ** ** ********* * *** ** *** * 'I': case 'i':     a[8]++;
**** * * ** ** * * * * * * ** *** * * *** * ** ** ** ** *** * * *** * ** * *** * * ****** * * * **** * ** * ** **** ** ** * *** ** *** ** * * * *** * * * ******** * **** *** *
* * * * * ** * ** **** * * * * * * ***** ***** * * ********* **** 'J': case 'j':     a[9]++;
* **** * * ** * * * * * ** ***** ***** * * *** *** * ** * * ** * ** ** ** *** * **** * * * * **** **** * **** * * * * * * ** ** ** ***** ** ** ** * * *** ** ***** **** * **** * ***** * * ** * * *
            case 'K': case 'k':     a[10]++;
* * * ** ** ** ** * ** * * * * * ********** * * * ******** ** ** * * ** * * **** *** ****** * * **** ** *** * * * *** * *** ** * ** * * * ** **** ** * * **** *** ** *** *
* * ** * ** * ** *** * *** * * ***** ** ***** * ** * * 'L': case 'l':     a[11]++;
* ****** * * *** *** *** ** *** * * ******* * * **** * ***** * ** * *** * * * **** * ********* * * ***** *** **** ** * * * *** * ** * * *** ** *** ** * ** *** ** * ** * * * * *** ******** ** * * * *
* *** * * ** * *** * ** *** ** ** * * * ** ** ** * * *** 'M': case 'm':     a[12]++;
* ** * ** * * ** ** *** ** * * *** ** * * * ** ******* ** * ** * *** ***** * * ** ***** ** ** * * ** *** * * * * * ** * * *** * * * * * **** ** * ** * * ** * ** *** ** ** * * **
* *** *** * ***** *** ** * * * ** ****** ******* ** *** * ** ***** * 'N': case 'n':     a[13]++;
*** **** ** * * ** ** *** ** * ** ** **** ** * * * ** ** ** ** ** ***** * ***** ***** ** * * *** * **** *** ** * * * * ** ***** ***** * ** ** * * ** * * * * * * ** ** * ** ** *** *
* *** ** * *** * ** * * ** * * ** * * ** *** *** *** * 'O': case 'o':     a[14]++;
************ ** ** * *** * * * * * *** * * *** * ****** * ** * * * * * * *** * * ** ** * ** ** *** ** * *** * ***** ** *** * **** * * * *** ** * * * ** ****** ** ** **** ** * *
** ** * * ** * * *** ** * * ** ** * *** * ** * *** **** * * * * 'P': case 'p':     a[15]++;
** *** *** * **** * * * * * **** * ** ***** ** * * * * *** *** * * * * * **** *** * ** * *** * * * ******* *** * * * *** * *** **** * *** ** * *** * * **** *** **** *** * *** ** *** * * **
* ** * ** ** ** * * * * ****** **** ** * * ** * ****** * * * 'Q': case 'q':     a[16]++;
**** ** * ** ** ** * * * *** *** **** *** * * ** * ** ** ** * ** * * ** ** *** * **** * **** * * ** * ** * *** ** * * ***** ****** *** *** * * * * **** ** * * ** ******* * ** *** ***
** * ** * * * **** *** * **** *** * ** ** * ******* * ** ** 'R': case 'r':     a[17]++;
**** ** * *** * ********* ***** * * * *** ** *** *** **** * * *** ** * *** * **** ** ** ** ****** * ***** *** * * * * * *** ** * **** **** * * ** * * ** * *** * ** *** * ** *** * * ** ** * * * *
**** ** * ** * ** **** * * ** ****** * * *** ** ** ** ***** * * * ** 'S': case 's':     a[18]++;
** **** * * * ** * ** * ** * * * * **** * * * ** * * * *** ** * *** ** * *** * ** * ***** **** ** ***** ** *** * ** ** * * ** * ** **** ** * * ** ** * * * * * * * ** * ***
*** ** ** * ** *** * * ** *** * * * *** *** ** * * *** * 'T': case 't':     a[19]++;
** *** ** ** *** * ******** ** * * *** * * ** ****** ** *** * ** * * * * * ** * * * **** * * * * * *** * * ** * * * * * ***** * *** *** * * **** ** * *** * * ** **** ** *** * ** *
* * * * ** ** *** * * * *** ***** * * ** * ** * *********** * * * * * * 'U': case 'u':     a[20]++;
* * * * * * * ** * ** * * * * * * ** * ** * *** ** ** ** ** * *** ** * * ** * ** ****** * ** ** ** ** * * * * *** *** ** * * **** * **** *** * * ** ** * ** ** *** **
**** **** * * ** **** *** ***** * * ***** *** * *** ** * * * ** * 'V': case 'v':     a[21]++;
** * * *** ** * * ******** * * * * * *** * * *** *** * ** * * ** * ** ** * * ** * * * *** * *** * *** * ** ** * ** ** * **** ** * ** * * * * ** *** ** * ** ** ** *** ** ** * ** ** *** **
* * ***** ** * ** ****** ** **** * ****** *** * *** * *** * *** * 'W': case 'w':     a[22]++;
**** *** * ** ***** * ** * **** ** ****** * * ** ** *** * ** ** ** * * *** ********* *** * * ** * * *** * *** ** * ** * **** ** * ** ** * *** ****** **** * * * ** * * * ** ***** *
* * *** * * ** * * * *** * * ** ** **** **** **** ** ** *** *** ******* **** 'X': case 'x':     a[23]++;
** * * * * *** **** *** * * * * * * ***** * * * *** * **** * *** **** ** * *** * * *** ** ** * * *** * *** *** ** * * ******** ** ** * * *** *** ** * * * * ***** *** ****** * * * ** * ** *** ** *
* * * **** * * ** ** * * * * * * * ** * * * * *** **** ** * * * ** * 'Y': case 'y':     a[24]++;
**** * * * ****** * * * *** * * *** ** ** **** ** * *** * ** * * ** * ****** ***** * * * ** *** * ** ** ** ** ** * * ** * * * ** * *** * ** ***** ***** * * ******** * **** * ***** ** ** ** * ** * ** * * * *
* * ******** ** ** ***** * **** * * ** ** **** **** * 'Z': case 'z':     a[25]++;
*** * ** ******* **** *** * ** ****** **** * * * *** ** ** ***** **** * * *** * **** **** ** * ******* * * **** ** * *** ** * ** * * ** **** ** ******** **** *** * ****** **
        }
    for(i=0;i<1000;i++){
        switch(B[i]){
* ** * * *** * ****** ** ***** * ** *** ** * * * * ** ** ** 'A': case 'a':     b[0]++;
** * * **** *** * *** * ** * * ** *** ** ** * ** ** * * ** * * * * * ** * ** *** ** ** ** * ** **** * * ** * ***** * ** * ** ** * *** ** ******* ***** **** * * * * * * * ** *
** * * ** * * * * * * * ** ** *** **** * ** * * * * ** * 'B': case 'b':     b[1]++;
** *** *** *** * * * *** ** * * ** ****** * * **** ** * ** * * * *** ** * **** *** ** ***** * * * * ***** * ** * ** *** ** ** * *** * * ** * * ** ** * * ** *** * * **** *** * ** ** *
** * * * ** ** ** ** * * * * * * ** ** *** * ** * *** **** ** ** 'C': case 'c':     b[2]++;
** **** * * ***** * * * * * * * * ** ** ** *** * * ***** * *** ** * ** * * * * *** ** ****** * ***** * ** * * *** * * ** ** ***** * ***** ****** * ** * * * * * *** ** * *** **
** ** ** ** * *** ** ** *** *** ** * ** *** ** * ** ** * * 'D': case 'd':     b[3]++;
* ** ** ** *** *** ** ** **** * *** * ** ** * ****** * ** * * * * **** ** ** * ** ** * * * * **** * *** * * * * *** ** * ** * ** * * ******** ** * ******* * ** * * ** * * **** ****** *
* * * * * *** ** ** * ********* ** ** ** ** *** ** 'E': case 'e':     b[4]++;
**** *** * ** * * * * * * * * ** * *** ** * ** ******** *** *** * * ******** ** * * ** * ** ***** ** ***** * * * ** *** ** *** * * ** * * ** ** * * * * **** ** * ** * * ** * *** **** **
* * * *** ** ** * ** * ** *** ** ** *** ****** * * **** 'F': case 'f':     b[5]++;
**** ** * *** ** ** ** * ** * ** * * * *** *** * ** ***** *** * * * **** * *** ** ** ***** * ** * *** * ** * * *** **** * * **** * * * ** **** ** * * ** * **** * * *** *** ***
* * ** ** *** * ***** * * ** *** * * * ** ****** ********* * ******* * 'G': case 'g':     b[6]++;
* * *** * *** * * ** ** ** ******* * * ***** * * *** **** * * ** * ** *** ** ** * * * ** * ********* * ****** * * * * ** ** *** * ** ** * ** * * ***** * ** ******* ** ** *** ** **
** * ** * * * ** *** ** * * * * * **** ** *** ** *** *** *** * 'H': case 'h':     b[7]++;
*** * * * * * ** * * ** ** * * *** * * * * * ** * **** ** *** ** * * *** **** ***** * * * * * * *** * * ** * ** * *** **** * ** ** * * * * * * * ** * ** **** ***** * ***
* ** ** * * ** ** **** ** * * * * * * *** * * * **** * * * 'I': case 'i':     b[8]++;
* * **** **** * *** * * * ** * ** * * * * ** * ** * *** ** * *** * *** * * * *** ** * **** * ******** * *** * ** ** **** ** * ** * *** * * * * ** *** ** ** * * * ** **
* ** ** ** * * * * * ** * * ** * **** *** ** ** ** ***** 'J': case 'j':     b[9]++;
* ***** * **** **** *** ** ** ** *** *** ** * *** * * * * * *** * * *** *** ** * ** * ****** *** *** ******* ** * *** ** * ****** ** * *** * * ** * *** ****** * * *** **** ** ** ****** **
* *** * * *** ** * ** **** * * *** * *** **** * * * * *** ***** ** ** 'K': case 'k':     b[10]++;
*** ** ** ** **** * *** ** * * ***** * ** * **** ** ******* * * * * **** ************ * * *** **** **** *** **** * **** ** * * *** * * * ** * ** * * * ** * ***** * * ** **** *** ** * * ***** *
            case 'L': case 'l':     b[11]++;
* * ** * * * ** *** * * ** *** ******* * ** ** ** ** *** * ** * * **** * ** ** **** * **** *** * *** * **** ** * * * ** ** * * ** * **** * * * * * *** *** *** * *
* * * ** * * * * ****** ** * ** ** * ** ** ** * * ** * * 'M': case 'm':     b[12]++;
** **** ** ** * * * *** * ** * ** * *** ** * *** * *** * *** * * **** * * ** **** *** ** * ****** ******** ** *** *** * **** * * * * * * * * * ** * * *** *** ** * *** * * ******* * * * ***** * ****
* ** * * * ** ** ** * * ** * * ** * * ** *** * * ** *** * * ** 'N': case 'n':     b[13]++;
* * * ***** * ** *** *** * *** * * * * * *** * *** * * * * ** ** * * * * * **** * * **** ** *** ****** * ** * **** * * ** * * * * * * ** * * * * *** ***** * ** * ** *** *** * *
* * **** * *** **** ** * * * ** ** * ** * ** ** * *** **** * ** ** 'O': case 'o':     b[14]++;
* * *** ******** * * ****** * ** ** * ** * ** * *** * * ** * * ***** * * ***** *** * *** ** * * * * * * ***** * ** * * ***** * * * *** ** *** * ** *** * * ** ** *** * * *
            case 'P': case 'p':     b[15]++;
* ** * *** ** ** * *** * *** * * * **** *** * * * * * *** * * ** * ** ** ** * ** *** * ** * *** * * ** ******* ** * * * * * * * * ** * * * * * * * * * ** ***** ******* * *
***** ** ***** ** **** * ** **** **** * ** ** * **** * ** 'Q': case 'q':     b[16]++;
* *** * **** * * **** ** * ****** *** * *** * ** * ** * * ** * * * * ***** * * * *** *** ** ** *** * * *** * *** * * ** * * *** *** * * * ********* ** **** *** ** ** ** * ** * *
* * ******* **** * *** * * * ** * *** * * **** * * * * * * * ** *** 'R': case 'r':     b[17]++;
* * ***** *** ** ** ** * * ** *** * ** *** ** *** * * * ** ** * ** *** ** *** * * ** ** *** * * * ** ***** *** *** * * *** ** * * * * * * ** * * * * * *** * ** **** * *** *** **
* *** * * *** ** ** ** ***** ** ** ** * *** ****** ** ** ** * * * *** 'S': case 's':     b[18]++;
*** * ** ** * * ****** ** * **** * * ***** ** * * * ***** ** * * * ***** ****** * *** ** ** **** * ** ** ** *** ** *** * * *** ****** ** * * *** * * ** ** * **** *****
* * * * * * * * * * ** * * ** * *** ** * ********** *** * 'T': case 't':     b[19]++;
* ***** ** **** *** ** * * *** * *** * * **** *** * *** * ** *** *** * * *** ** * * ** * * ** **** **** * * ** * *** * * * * *** * * * * ***** * ** * * ** * ** * ** ** * * ** * *
** ** * * ** * * *** *** * * * * ** ** *** ** ** * ** * 'U': case 'u':     b[20]++;
* * * * * * * ** *** ** * * * ** *** ** * * ****** ** ***** * * **** ***** ** * ** *** **** * ** * ** * * * * **** * ** ***** * *** * ** * * * ****** ** ** * ** * * * ** ** * * **
** *** ** * * *** * * * ** ***** * * *** ** * *** * * * * * * ** 'V': case 'v':     b[21]++;
*** * *** * * ****** * ** ** * *** * * ** ***** * **** ** * * ** *** * *** * **** ***** * * * ****** *** * * * ** * * ***** * ***** **** * * *** * *** * ****** * * **** * * * * * *
** *** *** ** ***** *** ** *** ** * **** * * **** ** * *** * * 'W': case 'w':     b[22]++;
* **** * * *** ** ***** * * * * ******** **** ****** ** * *** * * * ** * * ** ** * * ** *** ** **** *** * * * * ** * * * ***** ** * * ** *** *** ** *** * **** * ** ** * ** ***
* * * * ** * * * * * *** * ** ** * * * * * *********** 'X': case 'x':     b[23]++;
* ** * * ** **** ** **** * * * ** *** **** * * ** * ** ** * ** ** **** * *** *** * ***** ** ** *** * ***** ** *** * **** * ** ** *** ** * * * ** * * * * * *** **** ** * * ** * *** * ** ***** *
* *** ***** * *** **** ** * * * ** * *** ***** ** ***** * **** ** 'Y': case 'y':     b[24]++;
** * * *** ** * * ****** * * **** ** ***** ******* *** * * * * ********** ** * **** * * *** **** *** * **** ** * ** * **** ** *** **** *** ** ** ** * * * **** * *** ** * * ** * * * ** ** *** ** ***** *
            case 'Z': case 'z':     b[25]++;
** * * **** ** * ****** * ******** * * * * * *** ** *** * ** *** * *** *** * **** ** * ** **** ***** ** * *** * * * * *** *** ******** **** ** ** * ***** * ** * * ** * ** ** *** * * ******** * *** *** *
        }
        for(i=0;i<26;i++){
*** ** *** * *** ** * **** ** * ** * *** ** * *** ** * ******* **
** * *** **** ** ** ** ** * ** *** ** * ** *** *********** ** *** ** ***** *** * * * ** 0;
        }
        return 1;
    //l=strlen(A);
    /*for(i=0;i<l;i++){
        for(j=0;j<l;j++){
* * ** ** * * * ** ***** **** * *** *** ** * * ** * *** ** ** * *** * * **
*** ** ** **** ***** ** * ** * ** ***** ** * **** ** *** * ** * *** * *** **** * * ** * *
* * * * *** * * ** * *** ******* ** ** ** **** *** *** **** * * ** * * *
            }
        }
    }
    printf("%d %d",l,sum);
    if(sum==l)
        return 1;
    else
        return 0;*/
}

int main(void)
{
    char A[100]={},B[100]={};
    fgets(A,100,stdin);
    fgets(B,100,stdin);
    if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
    else printf("Two words or phrases are not anagrams");

    return 0;
}
answered by (54 points)
0 0
prog.c: In function 'is_anagrams':
prog.c:147:1: error: expected declaration or statement at end of input
 }
 ^
prog.c:147:1: error: expected declaration or statement at end of input
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.179.63
©2016-2025

Related questions

0 like 0 dislike
47 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 35785 - Available when: 2017-12-07 18:00 - Due to: Unlimited
| 9.8k views
0 like 0 dislike
45 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 35784 - Available when: 2017-12-07 18:00 - Due to: Unlimited
| 9.6k views
0 like 0 dislike
41 answers
[Exercise] Coding (C) - asked Dec 14, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 37370 - Available when: 2017-12-14 18:00 - Due to: Unlimited
| 8.8k views
12,783 questions
183,442 answers
172,219 comments
4,824 users