Input Format:
Input consists of n+1 lines.
The first n lines contain strings corresponding to the words in the chain.
The last line of input contains the string #### to mark the end of input.
Output Format:
The output consists of the valid wordakshari chain.
The first word can begin with any letter.
Sample Input:
architect
tailor
referee
electrician
nurse
blacksmith
####
Sample Output:
architect
tailor
referee
electrician
nurse
SOLUTION:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string word[100];
int i = 1;
getline(cin,word[0]);
while(word[i - 1] != "####"){
getline(cin,word[i]);
i++;
}
int j;
cout<<word[0]<<endl;
for(j = 0; j < i-1; j++){
if(word[j].back() == word[j+1].front()){
cout<<word[j+1]<<"\n";
}
}
}
No comments:
Post a Comment