#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
  // Get number of files, call it N
  int N;
  cout << "Enter number of files: ";
  cin >> N;

  // Read and store the N file names
  string *NAME = new string[N];
  cout << "Enter file names: ";
  for(int i = 0; i < N; i++)
    cin >> NAME[i];

  // Create an array of N ofstreams
  ofstream *FILE = new ofstream[N];
  for(int j = 0; j < N; j++)
    FILE[j].open(NAME[j].c_str());

  // Read sentence and write to files
  cout << "Write sentence terminated by the word end: ";
  string s;
  for(cin >> s; s != "end"; cin >> s)
  {
    for(int k = 0; k < N; k++)
      FILE[k] << s << " ";
  }

  return 0;
}