Respuesta :
Solution and Explanation:
// code
#include <iostream>
#include <vector>
using namespace std;
// this function returns true if given character is in given word
bool has_char(string temp, char c)
{
for (int i = 0; i < temp.length(); i++)
if (temp[i] == c)
return true;
return false;
}
int main()
{
int n;
vector<string> words(n);
char character;
// read integer
cin >> n;
// read list of words
for (int i = 0; i < n; i++)
cin >> words[i];
// read a character
cin >> character;
// print those words which contains given character
for (int i = 0; i < n; i++)
{
if (has_char(words[i], character))
cout << words[i] << " ";
}
cout << endl;
}
Following are the progrm to matched the input value.
Program Explanation:
- Include header file.
- Defining a main-method.
- Inside the method three integer variable "n, i, j", one array of string "l" , one string variable "s", and one character (char) variable "c" is defined.
- In the next step, "n,l, s, and c" is used to input value, and define a for loop is defined that use if block to check string value contain the char value , and prints its value.
Program:
#include <iostream>//header file
using namespace std;
int main()//main method
{
int n,i,j; //defining integer variable
string l[n];//defining an array of string
string s;//defining a string variable
char c;//defining a char variable
cin>>n;//input n value
for(i = 0;i<n;i++)//defining loop to input string value
{
cin>>l[i];//input string value
}
cin>>c;//input char value
//defining loop that check string value contain input character value
for(i = 0;i<n;i++)
{
for(j = 0;j<l[i].length();j++)//defining loop that check string value
{
if(l[i][j]==ch)//using if block that check string value equal to character value {
cout<<l[i]<<endl;//print matched value
break;//break the condition
}
}
}
return 0;
}
Output:
Please find the attached file.
Learn more:
brainly.com/question/13543413
