Sentence Deobfuscate Name this file deobfuscate.cpp Hints: Don’t overthink this problem. Prompt the user to enter a collection of sentence words (i.e., words in the sentence), with the spaces removed (i.e., the obfuscated sentence) and with words that are less than ten (10) letters each. Then prompt the user to enter a sequence of numbers that represent the length of each corresponding sentence word (i.e. the deobfuscated details). Output the deobfuscated sentence. Convert char c to int by subtracting 48 (‘0’) from c.
Sample Execution:
Please enter obfuscated sentence: Thisisasentence
Please enter deobfuscation details: 4218
Deobfuscated sentence: This is a sentence

Respuesta :

Answer:

In C++:

#include <iostream>

using namespace std;

int main(){

   string text,lengt;

   cout<<"Please enter obfuscated sentence: ";    cin>>text;

   cout<<"Please enter deobfuscation details: ";    cin>>lengt;

   string t1, t2;

   int kount = 0;

   for(int i = 0;i<lengt.length();i++){

   kount+=(int)(lengt[i]-'0');

   t1 = text.substr(0, kount);

   t2 = text.substr(kount, text.length()-1);

   text = t1 +" "+ t2;

   kount++;   }

   cout<<"Deobfuscated sentence: "<<text;

   return 0; }

Explanation:

This declares the text and the deobfuscation details as string

   string text,lengt;

This prompts for the sentence

   cout<<"Please enter obfuscated sentence: ";     cin>>text;

This prompts for the details

   cout<<"Please enter deobfuscation details: ";     cin>>lengt;

t1 and t2 are declared as string. They are used to split the texts into 2 parts

   string t1, t2;

This declares and initializes a count variable to 0  

   int kount = 0;

This iterates through the deobfuscation details

for(int i = 0;i<lengt.length();i++){

This gets each deobfuscation character

   kount+=(int)(lengt[i]-'0');

The next two instructions splits the text into 2

This gets from 0 to kount.

   t1 = text.substr(0, kount);

This gets from kount to the last index

   t2 = text.substr(kount, text.length()-1);

The new string or sentence is calculated here

   text = t1 +" "+ t2;

The kount variable is incremented by 1

   kount++;   } The loop ends here

This prints the new sentence

   cout<<"Deobfuscated sentence: "<<text;

See attachment for program file

Ver imagen MrRoyal