Advertisement
Guest User

Untitled

a guest
Dec 7th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.17 KB | None | 0 0
  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 ConsoleApplication1 {
  9.     class Program {
  10.         public struct Keyy {
  11.             public unsafe fixed byte data[255];
  12.         }
  13.         public static void Main(string[] args) {
  14.             Console.WriteLine("Read from file");
  15.             //StreamReader readFromFile = File.OpenText(@"D:\MyText.txt");
  16.             Encoding enc = Encoding.GetEncoding(1251);
  17.             StreamReader readFromFile = new StreamReader(@"D:\test.txt", enc);
  18.             System.IO.StreamWriter file;
  19.             System.IO.File.Delete(@"D:\test1.txt");
  20.             string Words = readFromFile.ReadToEnd();
  21.             int amountOfWords = 0, k = 0, max = 0;
  22.             List<string> arrayOfWords = new List<string>();
  23.             arrayOfWords.Add("");
  24.             Keyy current;
  25.             Dictionary<Keyy, List<string>> dict = new Dictionary<Keyy, List<string>>();
  26.             foreach (char charFromString in Words) {
  27.                 if ((charFromString == ' ') || (charFromString == '\n')) {
  28.                     arrayOfWords.Add("");
  29.                     amountOfWords++;
  30.                 }
  31.                 else {
  32.                     arrayOfWords[amountOfWords] += charFromString;
  33.                 }
  34.             }
  35.             if (amountOfWords == 0) {
  36.                 Console.WriteLine("There is only one word in text!");
  37.             }
  38.             else {
  39.                 using (file = new System.IO.StreamWriter(@"D:\test1.txt", true)) {
  40.                     for (int i = 0; i <= amountOfWords; i++) {
  41.                         k = 1;
  42.                         unsafe {
  43.                             current.data[0] = Convert.ToByte(arrayOfWords[i].Length);
  44.                             string ex = arrayOfWords[i];/*
  45.                             for(int ii = 1; ii < ex.Length; ii++) {
  46.                                 current.data[ii] = Convert.ToByte(ex[ii - 1]);
  47.                             }*/
  48.                             for(int ii = 0; ii < ex.Length; ii++) {
  49.                                 Console.WriteLine(Convert.ToByte(ex[ii]));
  50.                             }
  51.                             for (int ii = 1; ii < 254; ii++) {
  52.                                 for (int j = ii + 1; j < 255; j++) {
  53.                                     if (current.data[j] < current.data[ii]) {
  54.                                         byte temp = current.data[i];
  55.                                         current.data[ii] = current.data[j];
  56.                                         current.data[j] = temp;
  57.                                     }
  58.                                 }
  59.                             }
  60.                         }
  61.                         List<string> a = new List<string>();
  62.                         a.Add(arrayOfWords[i]);
  63.                         //dict.Add(current, a);
  64.                         if (dict.ContainsKey(current)==false) {
  65.                             dict.Add(current, a);
  66.                         }/*
  67.                         file.Write(arrayOfWords[i] + " ");
  68.                         for (int j = 0; j <= amountOfWords; j++) {
  69.                             if (((String.Equals(arrayOfWords[i], arrayOfWords[j]) == false)
  70.                                     && (arrayOfWords[i].Length == arrayOfWords[j].Length))
  71.                                     && ((String.Equals(string.Concat(arrayOfWords[i].ToLower().OrderBy(x => x).ToArray()), string.Concat(arrayOfWords[j].ToLower().OrderBy(x => x).ToArray())))
  72.                                     )) {
  73.                                 file.Write(arrayOfWords[j] + " ");
  74.                                 k++;
  75.                             }
  76.                         }
  77.                         file.WriteLine();
  78.                         if (k > max) max = k;*/
  79.                     }
  80.                 }
  81.             }
  82.             Console.WriteLine("Maximal Amount of Anagramm Words = {0}", max);
  83.             Console.ReadKey();
  84.  
  85.             //            current.data[0] = calc_symbols_in_word(word);
  86.             //          for (int i = 1; i < 256; i++) {
  87.             //            current.data[i]=word[i-1]
  88.         }
  89.    }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement