package com.javarush.task.task22.task2209;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Составить цепочку слов
*/
public class Solution {
public static void main(String[] args) throws IOException {
//...
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
FileInputStream file = new FileInputStream(reader.readLine());
reader = new BufferedReader(new InputStreamReader(file));
String str = new String();
while (reader.ready()) {
str += reader.readLine();
}
reader.close();
String[] arrWords = str.split(" ");
String[] nul = new String[0];
StringBuilder result = getLine();//C:/dat.txt//arrWords
System.out.println(result.toString());
}
public static StringBuilder getLine(String... words) {
StringBuilder res = new StringBuilder("");//
if(words==null|| words.length==0) return res;
res.append(words[0]);
String lastChar = "";
String firstChar = "";
for(String s : words) {
lastChar = res.substring(res.length()-1);
res.append(" ");
for(int i = 1; i < words.length; i++) {
firstChar = String.valueOf(words[i].charAt(0));
if(lastChar.equals(firstChar.toLowerCase())) {
res.append(words[i]);
}
}
}
res.deleteCharAt(res.length()-1);
return res;
}
}