ASSIGNMENT -6
Question 1.
Solution:
#include <stdio.h>
int check_anagram(char [], char []);
void main()
char a[100], b[100];
int flag,i,count=0;
scanf("%[^\n]%*c", a);
scanf("%[^\n]%*c", b);
flag = check_anagram(a, b);
if (flag == 1)
for(i=0;a[i]!='\0';i++){
if(a[i]==b[i])
count++;
}
printf("%d",count);
else
printf("-1");
int check_anagram(char a[], char b[])
int first[26] = {0}, second[26] = {0}, c = 0;
while (a[c] != '\0')
first[a[c]-'a']++;
c++;
c = 0;
while (b[c] != '\0')
{
second[b[c]-'a']++;
c++;
for (c = 0; c < 26; c++)
if (first[c] != second[c])
return 0;
return 1;
Question 2:
Solution:
#include <stdio.h>
#include <stdlib.h>
struct node
int vertex;
struct node *next;
};
struct list_entry
struct node *head;
struct node *tail;
};
struct list_entry list_entries[34000];
void init_list_entries()
int i;
for ( i=0 ; i<100 ; i++ )
list_entries[i].head =
list_entries[i].tail =
NULL;
}
}
struct node * make_node ( int data )
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp -> vertex = data;
temp -> next = NULL;
return temp;
void insert_at_end(int a, int b)
struct node *node1;
struct node *node2;
node1 = make_node (a);
if(list_entries[b].head == NULL)
list_entries[b].head = node1;
list_entries[b].tail = node1;
else
list_entries[b].tail->next = node1;
list_entries[b].tail = node1;
node2 = make_node(b);
if(list_entries[a].head == NULL)
{
list_entries[a].head = node2;
list_entries[a].tail = node2;
else
list_entries[a].tail->next = node2;
list_entries[a].tail = node2;
return;
void print_adjacent_vertices_of(int n)
struct node *current = list_entries[n].head;
while(current != NULL)
printf("%d\n",current->vertex);
current = current->next;
return;
int main()
int num_edges;
int a;
int b;
int n;
int i=0;
scanf("%d", &num_edges);
for ( i=0; i<num_edges ; i++)
scanf ( "%d", & a);
scanf ( "%d", & b);
insert_at_end(a,b);
scanf("%d",&n);
print_adjacent_vertices_of(n);
}
Question 3.
Solution:
#include <stdio.h>
#include<string.h>
int longestRun(char []);
void main()
char a[100];
int count=0;
scanf("%[^\n]%*c", a);
count = longestRun(a);
printf("%d",count);
int longestRun(char a[])
int c = 0,n=1,max_len=1;
for (c ; c < strlen(a); c++)
{ if(a[c]==a[c+1]){
n++;
else{
if(n>max_len)
max_len = n;
n=1;
return max_len;