SHARE
TWEET

Untitled

a guest May 22nd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace ConsoleApp2
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.            
  15.             List<int> evenNumbers = new List<int>();
  16.             List<int> oddNumbers = new List<int>();
  17.  
  18.             StreamReader MyFile = new StreamReader("in.txt");
  19.             string MyString = MyFile.ReadToEnd();
  20.             MyFile.Close();
  21.  
  22.  
  23.             StreamWriter evenWriter = new StreamWriter("even.txt");
  24.             StreamWriter oddWriter = new StreamWriter("odd.txt");
  25.  
  26.             string[] words = MyString.Split(null);
  27.             int[] numbers = Array.ConvertAll(words, int.Parse);
  28.  
  29.  
  30.             foreach (int i in numbers)
  31.             {
  32.                 if(numbers[i]%2==0)
  33.                 {
  34.                     evenNumbers.Add(numbers[i]);
  35.                     evenWriter.Write(numbers[i] + ",");
  36.                 }
  37.                 else
  38.                 {
  39.                     oddNumbers.Add(numbers[i]);
  40.                     oddWriter.Write(numbers[i] + ",");
  41.                 }
  42.             }
  43.  
  44.             evenWriter.Close();
  45.             oddWriter.Close();
  46.  
  47.         }
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top