0% found this document useful (0 votes)
6 views5 pages

Coding Assignment: Palindrome, Anagram, Pangram

The document contains three coding assignments related to string manipulation in C++. The first assignment involves determining the minimum number of character removals needed to form a palindrome, the second checks if two strings are anagrams, and the third verifies if a given string is a pangram. Each assignment includes code snippets, input examples, and expected output.

Uploaded by

syfuddinhome
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)
6 views5 pages

Coding Assignment: Palindrome, Anagram, Pangram

The document contains three coding assignments related to string manipulation in C++. The first assignment involves determining the minimum number of character removals needed to form a palindrome, the second checks if two strings are anagrams, and the third verifies if a given string is a pangram. Each assignment includes code snippets, input examples, and expected output.

Uploaded by

syfuddinhome
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

CODING SKILLS ASSIGNMENT – 1

NAME : [Link]
AP24110011779
SEACTION : ‘A’
1)Given a string . Task is to find how many minimum characters
are to be removed from the given string to form a palindrome?
Code:
#include<iostream>
#include<string>
using namespace std;
int main() {
string s = "aabbc";
int freq[26] = {0};
//count frequence of characters
for (char c:s) {
freq[c - 'a']++;
}
int oddcount = 0;
for(int i = 0; i < 26; i++){
if(freq[i]%2 != 0){
oddcount ++;
}
}
int removals = (oddcount == 0)?0:oddcount - 1;
cout<<"minimum removals = "<< removals<<endl;

return 0;
}

Code input and output


Input : aabbc
Output : oddcount = 1
So removals = 0.

2)Given two strings . How do you check the two strings are
anagrams .
Code :
#include<iostream>
#include<string>
using namespace std;
bool areanagrams(string s1,string s2) {
if([Link]()!=[Link]())
return false;
int f1[26] = {0},f2[26] = {0};
for(char c:s1)f1[c-'a']++;
for(char c:s2)f2[c-'a']++;
for(int i=0;i<26;i++) {
if(f1[i]!=f2[i])
return false;
}
return true;

}
int main() {
string s1 = "abc",s2 = "cab";
if(areanagrams(s1,s2))
cout<<"anagram"<<endl;
else
cout<<"not anagram";
return 0;
}

Code input and output


Input :
s1 = “abc”
s2 = “cab”
output : anagram
3)Check whether the given string is pangram or not?
Code :
#include <iostream>
#include <string>
using namespace std;

int main() {
string s;
getline(cin, s); // read full line (with spaces)

bool present[26] = {false};

for (char c : s) {
if (c >= 'A' && c <= 'Z')
present[c - 'A'] = true;
else if (c >= 'a' && c <= 'z')
present[c - 'a'] = true;
}

bool isPangram = true;


for (int i = 0; i < 26; i++) {
if (!present[i]) {
isPangram = false;
break;
}
}

if (isPangram)
cout << "Yes, it is a Pangram" << endl;
else
cout << "No, it is not a Pangram" << endl;

return 0;
}

Code input and output


Input: A quick brown fox jumps over the lazy dog
Output: Yes, it is a Pangram

You might also like