Sagot :
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