Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void PrintMixedText(string fout, List<string> wordsFirstFile, List<string> wordsSecondFile)
- {
- int indexFirst = 0,
- indexSecond = 0;
- using(var writer = File.CreateText(fout))
- {
- string conditionWord = wordsSecondFile[indexSecond];
- StringBuilder line = new StringBuilder();
- while(indexFirst < wordsFirstFile.Count - 1 && indexSecond < wordsSecondFile.Count - 1)
- {
- while (wordsFirstFile[indexFirst] != conditionWord && indexFirst < wordsFirstFile.Count - 1)
- {
- line.Append(wordsFirstFile[indexFirst]);
- line.Append(" ");
- indexFirst++;
- }
- if (wordsFirstFile[indexFirst] == conditionWord)
- {
- if (indexFirst < wordsFirstFile.Count - 1)
- {
- conditionWord = wordsFirstFile[indexFirst + 1];
- }
- else//last word in file matched condition word
- {
- for (int i = indexSecond; i < wordsSecondFile.Count - 1; i++)
- {
- line.Append(wordsSecondFile[i]);
- indexSecond++;
- }
- line.Append(wordsFirstFile[indexFirst]); //last word
- //PABAIGA!!!!!!!! EXIT CIA KAZKAIP
- indexFirst = wordsFirstFile.Count;
- indexSecond = wordsSecondFile.Count;
- }
- }
- else
- {
- for(int i = indexSecond; i < wordsSecondFile.Count - 1; i++)
- {
- line.Append(wordsSecondFile[i]);
- line.Append(" ");
- }
- indexFirst = wordsFirstFile.Count;
- indexSecond = wordsSecondFile.Count;
- }
- while (wordsSecondFile[indexSecond] != conditionWord && indexSecond < wordsSecondFile.Count - 1)
- {
- line.Append(wordsSecondFile[indexSecond]);
- line.Append(" ");
- indexSecond++;
- }
- if (wordsSecondFile[indexSecond] == conditionWord)
- {
- if (indexSecond < wordsSecondFile.Count - 1)
- {
- conditionWord = wordsSecondFile[indexSecond + 1];
- }
- else
- {
- for (int i = indexFirst; i < wordsFirstFile.Count - 1; i++)
- {
- line.Append(wordsFirstFile[i]);
- //indexFirst++;
- }
- line.Append(wordsSecondFile[indexSecond]);
- //PABAIGA
- indexFirst = wordsFirstFile.Count;
- indexSecond = wordsSecondFile.Count;
- }
- }
- else
- {
- for (int i = indexFirst; i < wordsFirstFile.Count - 1; i++)
- {
- line.Append(wordsFirstFile[i]);
- line.Append(" ");
- }
- indexFirst = wordsFirstFile.Count;
- indexSecond = wordsSecondFile.Count;
- }
- }
- writer.WriteLine(line.ToString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement