0% found this document useful (0 votes)
5 views3 pages

Anagram Checker Program Code

The document contains a programming assignment for a word game where players check if two input words are anagrams. It includes the problem statement, example code in C++, and the status of the submissions, indicating that both solutions are correct with full marks. The first problem involves checking for anagrams, and the second problem requires searching for an element in an array.

Uploaded by

gbhargavchandra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Anagram Checker Program Code

The document contains a programming assignment for a word game where players check if two input words are anagrams. It includes the problem statement, example code in C++, and the status of the submissions, indicating that both solutions are correct with full marks. The first problem involves checking for anagrams, and the second problem requires searching for an element in an array.

Uploaded by

gbhargavchandra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VIT - Vellore

21

1
12

12

12
01
S0

S0

S0
S
BB

BB

BB

BB
Name: GUTHULA BHARGAVCHANDRA . Scan to verify results
23

23

23

23
Email: guthula.2023@[Link]
Roll no: 23BBS0121
Phone: 9999999999
Branch: MUKKU NISANTH KARTHEEK_DSA
Department: admin
Batch: VL2024250505225
Degree: admin
21

1
12

12

12
01

CBS3003_Design and Analysis of Algorithms_VL2024250505225


S0

S0

S0
BS

BB

BB

BB
B
23

23

23

23
VIT V_Scope_DAA_Week 3_COD_Medium

Attempt : 1
Total Mark : 20
Marks Obtained : 20

Section 1 : Coding

1. Problem Statement
1

21

1
12

12

12
01

Imagine you are creating a program for a word game where players can
S0

S0

S0
S
BB

BB

BB

check if two words they input are anagrams of each other. BB


23

23

23

23

An anagram is when the letters of one word can be rearranged to form


another word. For instance, 'listen' and 'silent' are anagrams because they
use the same letters.

Your program needs to analyze the input words provided by the players
and determine if they are anagrams. If the letters in both words can be
rearranged to form each other, the program should confirm that they are
indeed anagrams; otherwise, it should indicate that they are not.
1

21
12

12

12

01

This feature will enhance the players' experience, allowing them to


S0

S0

S0

S
BB

BB

BB

BB

challenge each other's word knowledge and problem-solving skills.


23

23

23

23
1

21

1
Answer
12

12

12
01
S0

S0

S0
S
#include<iostream>
BB

BB

BB

BB
#include<algorithm>
23

23

23

23
using namespace std;
bool check(string s1, string s2)
{
sort([Link](),[Link]());
sort([Link](),[Link]());
return s1==s2;
}
int main()
{
string s1,s2;
21

1
12

12

12
cin>>s1;
01

S0

S0

S0
BS

cin>>s2;
BB

BB

BB
B
23

23

23

23
if(check(s1,s2))
{
cout<<s1<<" and "<<s2<<" are anagrams."<<endl;
}
else
{
cout<<s1<<" and "<<s2<<" are not anagrams."<<endl;
}
1

21

1
12

12

12
return 0;
01
S0

S0

S0
S

}
BB

BB

BB

BB
23

23

23

23
Status : Correct Marks : 10/10

2. Problem Statement

You are given an array A of size N. You are given the number K which you
have to search in the array and return the index of that element.

If there are multiple matches, print the index of the first matched element.
1

21

If there is no match, print -1.


12

12

12

01
S0

S0

S0

S
BB

BB

BB

BB
23

23

23

23
Answer
1

21

1
12

12

12
01
S0

S0

S0
#include<iostream>

S
BB

BB

BB

BB
using namespace std;
23

23

23

23
int linear(int arr[],int n,int k)
{
int flag = 1;
for(int i=0;i<n;i++)
{
if(arr[i]==k)
{
flag = 0;
return i;
}
21

1
}
12

12

12
01

S0

S0

S0
if(flag=1)
BS

BB

BB

BB
{
B
23

23

23

23
return -1;
}
else{
return 0;
}

int main()
{
1

21

1
int n,k;
12

12

12
01
S0

S0

S0
cin>>n;
S
BB

BB

BB

cin>>k; BB
23

23

23

23
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int idx = linear(arr,n,k);

cout<<idx;

return 0;
1

21

}
12

12

12

01
S0

S0

S0

S
BB

BB

BB

BB

Status : Correct Marks : 10/10


23

23

23

23

You might also like