1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
int main(){
string str1, str2, str3, str4;
size_t found;
while (cin >> str1){
while (cin >> str2){
str4=str1+str2;
while (cin >> str3){
cout << "The New Set:" << endl;
cout << "First String is " << str1 << " and contains " << str1.length() << " characters." << endl;
cout << "Second String is " << str2 << " and contains " << str2.length() << " characters." << endl;
cout << "Third String is " << str1+str2 << " and contains " << str1.length() + str2.length() << " characters." << endl;
found=str1.find(str3);
if (found!= string::npos) {
cout << "The word '" << str3 << "' is found at position " << int(found) << "." << endl;
}
else
cout << "The word '" << str3 << "' is not found in the first string." << endl;
found=str2.find(str3);
if (found != string::npos) {
cout << "The word '" << str3 << "' is found at position " << int(found) << "." << endl;
}
else
cout << "The word '" << str3 << "' is not found in the second string." << endl;
found=str4.find(str3);
if (found != string::npos) {
cout << "The word '" << str3 << "' is found at position " << int(found) << "." << endl;
}
else
cout << "The word '" << str3 << "' is not found in the third string." << endl;
cout << "\n";
}
}
}
return 0;
}
|
CURRENT OUTPUT:
This.is.
a.nonsense.sentence.
ten
The New Set:
First String is This.is. and contains 8 characters.
Second String is a.nonsense.sentence and contains 20 characters.
Third String is This.is.a.nonsense.sentence and contains 28 characters.
The word 'ten' is not found in the first string.
The word 'ten' is found at position 14.
The word 'ten' is found at position 22.
WhyAmISo
The New Set:
First String is This.is. and contains 8 characters.
Second String is a.nonsense.sentence and contains 20 characters.
Third String is This.is.a.nonsense.sentence and contains 28 characters.
The word 'WhyAmISo' is not found in the first string.
The word 'WhyAmISo' is not found in the second string.
The word 'WhyAmISo' is not found in the third string.
silly?
The New Set:
First String is This.is. and contains 8 characters.
Second String is a.nonsense.sentence and contains 20 characters.
Third String is This.is.a.nonsense.sentence and contains 28 characters.
The word 'silly?' is not found in the first string.
The word 'silly?' is not found in the second string.
The word 'silly?' is not found in the third string.
sos
The New Set:
First String is This.is. and contains 8 characters.
Second String is a.nonsense.sentence and contains 20 characters.
Third String is This.is.a.nonsense.sentence and contains 28 characters.
The word 'sos' is not found in the first string.
The word 'sos' is not found in the second string.
The word 'sos' is not found in the third string.
EXPECTED OUTPUT:
A new set:
First string is “This.is.” and contains 8 characters.
Second string is “a.nonsense.sentence.” and contains 20 characters.
Third string is “This.is.a.nonsense.sentence.” and contains 28 characters.
The word “ten” is not found in the first string.
The word “ten” is found in the second string at position 14.
The word “ten” is found in the third string at position 22.
A new set:
First string is “WhyamIso” and contains 8 characters.
Second string is “silly?” and contains 6 characters.
Third string is “WhyamIsosilly?” and contains 14 characters.
The word “sos” is not found in the first string.
The word “sos” is not found in the second string.
The word “sos” is found in the third string at position 6.
The longest string contained 28 characters.
How can I edit my code to produce the expected output?