English, asked by nehafrooty1414, 5 hours ago

QUESTION A company has to tag its products. Each product has an associated product type which is used to tag the products. Product type is a sequence of lower-case letters from the English alphabet. The company want to have an algorithm for their system which takes the product type and outputs the tag. To generate the tag, pairs of adjacent characters are formed from the start of the uct type . From each pair the lexicographically smallest character will be removed. If a character will be left unpaired then that character will be taken as it is in the tag. Write an algorithm for the company system to find the tag for the given product.
Input
The input consists of a string productType. representing the product type of the product.
Output
Print a string representing the tag for the given product
eg:
input: electronics
output: letois

Answers

Answered by hemanthkumar7131
80

Answer:

#include<iostream>

#include<string>

using namespace std;

int main()

{

int i;

string s,ans;

cin>>s;

for(i=0;i<s.length();i+=2)

{

if(s[i]>s[i+1])

ans+=s[i];

else

ans+=s[i+1];

}

cout<<ans;

return 0;

}

Answered by mindfulmaisel
21

algorithm for the tag for the given product

Explanation:

algorithm for the company system to find the tag for the given product.

Input:

The input consists of a string product Type. representing the product type of the product.

Output:

Print a string representing the tag for the given product

algorithm:

x = input()

n = len(x)

ans = ""

for i in range(0, n, 2):

   if i==n-1:

       ans+=x[i]

   else:

       ans+=(x[i] if x[i]>x[i+1] else x[i+1])

print(ans)

hence, this is the algorithm for the company system to find the tag for the given product.

Similar questions