Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.97 KB | None | 0 0
  1. public static void PrintMixedText(string fout, List<string> wordsFirstFile, List<string> wordsSecondFile)
  2.         {
  3.             int indexFirst = 0,
  4.                 indexSecond = 0;
  5.             using(var writer = File.CreateText(fout))
  6.             {
  7.                 string conditionWord = wordsSecondFile[indexSecond];
  8.                 StringBuilder line = new StringBuilder();
  9.  
  10.                 while(indexFirst < wordsFirstFile.Count - 1 && indexSecond < wordsSecondFile.Count - 1)
  11.                 {
  12.                     while (wordsFirstFile[indexFirst] != conditionWord && indexFirst < wordsFirstFile.Count - 1)
  13.                     {
  14.                         line.Append(wordsFirstFile[indexFirst]);
  15.                         line.Append(" ");
  16.                         indexFirst++;
  17.                     }
  18.                     if (wordsFirstFile[indexFirst] == conditionWord)
  19.                     {
  20.                         if (indexFirst < wordsFirstFile.Count - 1)
  21.                         {
  22.                             conditionWord = wordsFirstFile[indexFirst + 1];
  23.                         }
  24.                         else//last word in file matched condition word
  25.                         {
  26.                             for (int i = indexSecond; i < wordsSecondFile.Count - 1; i++)
  27.                             {
  28.                                 line.Append(wordsSecondFile[i]);
  29.                                 indexSecond++;
  30.                             }
  31.                             line.Append(wordsFirstFile[indexFirst]); //last word
  32.                                                                      //PABAIGA!!!!!!!! EXIT CIA KAZKAIP
  33.                             indexFirst = wordsFirstFile.Count;
  34.                             indexSecond = wordsSecondFile.Count;
  35.                         }
  36.                     }
  37.                     else
  38.                     {
  39.                         for(int i = indexSecond; i < wordsSecondFile.Count - 1; i++)
  40.                         {
  41.                             line.Append(wordsSecondFile[i]);
  42.                             line.Append(" ");
  43.                         }
  44.                         indexFirst = wordsFirstFile.Count;
  45.                         indexSecond = wordsSecondFile.Count;
  46.                     }
  47.  
  48.                     while (wordsSecondFile[indexSecond] != conditionWord && indexSecond < wordsSecondFile.Count - 1)
  49.                     {
  50.                         line.Append(wordsSecondFile[indexSecond]);
  51.                         line.Append(" ");
  52.                         indexSecond++;
  53.                     }
  54.                     if (wordsSecondFile[indexSecond] == conditionWord)
  55.                     {
  56.                         if (indexSecond < wordsSecondFile.Count - 1)
  57.                         {
  58.                             conditionWord = wordsSecondFile[indexSecond + 1];
  59.                         }
  60.                         else
  61.                         {
  62.                             for (int i = indexFirst; i < wordsFirstFile.Count - 1; i++)
  63.                             {
  64.                                 line.Append(wordsFirstFile[i]);
  65.                                 //indexFirst++;
  66.                             }
  67.                             line.Append(wordsSecondFile[indexSecond]);
  68.                             //PABAIGA
  69.                             indexFirst = wordsFirstFile.Count;
  70.                             indexSecond = wordsSecondFile.Count;
  71.                         }
  72.                     }
  73.                     else
  74.                     {
  75.                         for (int i = indexFirst; i < wordsFirstFile.Count - 1; i++)
  76.                         {
  77.                             line.Append(wordsFirstFile[i]);
  78.                             line.Append(" ");
  79.                         }
  80.                         indexFirst = wordsFirstFile.Count;
  81.                         indexSecond = wordsSecondFile.Count;
  82.                     }
  83.                 }
  84.  
  85.              
  86.                 writer.WriteLine(line.ToString());
  87.             }
  88.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement