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

AP Exp 2.3

The document describes experiments to solve count and say problem and represent characters using 1 and 2 bits. It includes the aim, objective, algorithms and outputs for count and say problem and representing characters with 1 and 2 bits.

Uploaded by

Kunal shaw
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)
8 views3 pages

AP Exp 2.3

The document describes experiments to solve count and say problem and represent characters using 1 and 2 bits. It includes the aim, objective, algorithms and outputs for count and say problem and representing characters with 1 and 2 bits.

Uploaded by

Kunal shaw
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
You are on page 1/ 3

Experiment 2.

StudentName: Kunal Shaw UID: 21BCS2144


Branch: BE-CSE Section/Group:608/A
Semester: 6 Date of Performance:01-03-2024
Subject Name: Advance Programming lab
Subject Code:21CSP-251

1. Aim:
• To Solve Count and Say
• To Solve 1 bit and 2 bits characters
2. Objective:

• The count-and-say sequence is a sequence of digit strings defined by


the recursive formula: countAndSay(1) = "1" countAndSay(n) is the
way you would "say" the digit string from countAndSay(n-1), which is
then converted into a different digit string.

• We have two special characters: The first character can be


represented by one bit 0. The second character can be represented by
two bits (10 or 11).

3. Algo. /Approach and output:

class Solution {
public:
string countAndSay(int n) {
if(n == 1) return "1";
string s = countAndSay(n-1);
int i = 0, j = 0;
string r;
while(i < s.size()) {
j = i+1;
while(j < s.size() && s[j] == s[i])
++j;
string ct = to_string(j-i);
r += ct + s[i];
i = j;
}
return r;
}
};

class Solution {
public:
bool isOneBitCharacter(vector<int>& bits)
{
int n = bits.size();
if(n == 1)
return true;
int i = 0;
while(i <= n - 2)
{
if(bits[i] == 0)
i++;
else
i = i + 2;
}
if(i <= n-1)
return true;
else
return false;

}
};

You might also like