Name of The Course: Data Structures (DS) Assignment - 3: 1602-19-733-080 M. Meghana 19-11-2020
Name of The Course: Data Structures (DS) Assignment - 3: 1602-19-733-080 M. Meghana 19-11-2020
Assignment – 3
1602-19-733-080
M. Meghana
19-11-2020
SET I:
1. You have been hired by the government for their latest project. The country
consists of N cities and M roads. Roads are directional. There may be more
than one roads between some cities. The cities are numbered from 1 to N.You are
given Q queries, each query has two integers U and V. Your task is to print
the shortest path between city U and city V. If it is not possible to go from
city U to city V, then print -1.
InputFirst line consists of three integers N, M and Q.
Next M lines each consists of three integers u, v, and w denoting a bidirectional road
between city u and city v with length w.
Then Q lines follow, each line having two integers U and V.
Output
Print Q lines of output.
For each query print the length of the shortest path between U and V
Notes
1 ≤ N ≤ 200 1 ≤ M, Q, ≤ N × N
Sample Input 0
575
515
321
453
435
533
454
545
12
13
44
51
32
Sample Output 0
-1
-1
0
5
1
Program:
#include<stdio.h>
#include <conio.h>
}
Output:
case '>':
x = s.top;
pop();
if (x == '(' || x == '{')
return false;
break;
}
}
return (isEmpty());
}
int main()
{
int n;
scanf("%d",&n);
int i,count,countP=0,j,error=0;
for(i=0;i<n;i++)
{
count=0,error=0;
char str[20];
scanf("%s",str);
if(str[0]=='{')
{
if(str[strlen(str)-1]!='}')
{
printf("Compilation Errors\n");
error=1;
}
}
if(BracketsBalanced(str)==false)
{
printf("Compilation Errors\n");
error=1;
}
if(error==0)
{
for (j = 0; str[j] != '\0'; j++) {
if (str[j] == '<')
count++;
}
if (count == 0 || count>1)
{
printf("Compilation Errors\n");
error=1;
}
for (j = 0; str[j] != '\0'; j++) {
if (str[j] == 'P')
countP++;
}
if (count >100)
{
printf("Compilation Errors\n");
error=1;
}
int pos1,pos2,countO=0,countC=0,k;
for (j = 0; str[j] != '\0'; j++)
{
if(str[j]=='<')
pos1=j;
if(str[j]=='>')
pos2=j;
}
for(j=pos1+1;j<pos2;j++)
{
if(str[j]=='(')
{
printf("Compilation Errors\n");
error=1;
break;
}
}
for (j = 0; str[j] != '\0'; j++)
{
if(str[j]=='(')
{
countO++;
}
if(str[j]==')')
{
countC++;
if(countO==countC)
countO=countC=0;
else
{
printf("Compilation Errors\n");
error=1;
break;
}
}
}
for (j = 1; str[j+1] != '\0'; j++)
{
if(str[j]=='{')
{
for (k = j+1; str[k+1] != '\0'; k++)
{
if(str[k]=='}')
{
int l;
for(l=k+1;str[l+1]!='\0';l++)
{
if(str[l]=='(' || str[l]=='{')
{
printf("Compilation
Errors\n");
error=1;
break;
}
}
}
}
}
}
}
if(error==0)
printf("No compilation errors\n");
}
return 0;
}
Output:
3. Around 25 teams participated in a paper presentation contest. The Evaluators
have awarded marks to teams based on 3 criteria - depth of content,
presentation and communications skills. Each criteria allotted with 10 marks
each. Display the evaluation list in the decreasing order of their total marks
in all the 3 criteria. If the teams have same total mark then which team has
registered first will be placed first than the other one. Accept the input details as
described in the scenario and design a C program to display the evaluation
list. Use Quick Sort.
Program:
#include<stdio.h>
struct team
{
int id;
int total;
};
void swap(int *a, int *b)
{
int t=*a;
*a=*b;
*b=t;
}
int partition (struct team part[], int low, int high)
{
int pivot= part[high].total;
int i = (low - 1);
int j;
for (j = low; j <= high- 1; j++)
{
if(temp->data>root->data)
{
if(root->right!=NULL)
insert(root->right,temp);
else
root->right=temp;
}
}
struct node* search(struct node* root, int key){
if (root == NULL || root->data == key)
return root;
if (root->data < key)
return search(root->right, key);
return search(root->left, key);
}
int main()
{
struct node* temp;
int n,i,val,N,M;
scanf("%d",&n);
scanf("%d %d",&N,&M);
for(i=0;i<N;i++)
{
scanf("%d",&val);
temp=newNode(val);
if(root==NULL)
root=temp;
else
insert(root,temp);
}
for(i=0;i<M;i++)
{
scanf("%d",&val);
temp=newNode(val);
if(!search(root,val))
{
printf("NO\n");
temp=newNode(val);
insert(root,temp);
}
else
{
printf("YES\n");
}
}
}
Output: