Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace ConsoleApplication1 {
- class Program {
- public struct Keyy {
- public unsafe fixed byte data[255];
- }
- public static void Main(string[] args) {
- Console.WriteLine("Read from file");
- //StreamReader readFromFile = File.OpenText(@"D:\MyText.txt");
- Encoding enc = Encoding.GetEncoding(1251);
- StreamReader readFromFile = new StreamReader(@"D:\test.txt", enc);
- System.IO.StreamWriter file;
- System.IO.File.Delete(@"D:\test1.txt");
- string Words = readFromFile.ReadToEnd();
- int amountOfWords = 0, k = 0, max = 0;
- List<string> arrayOfWords = new List<string>();
- arrayOfWords.Add("");
- Keyy current;
- Dictionary<Keyy, List<string>> dict = new Dictionary<Keyy, List<string>>();
- foreach (char charFromString in Words) {
- if ((charFromString == ' ') || (charFromString == '\n')) {
- arrayOfWords.Add("");
- amountOfWords++;
- }
- else {
- arrayOfWords[amountOfWords] += charFromString;
- }
- }
- if (amountOfWords == 0) {
- Console.WriteLine("There is only one word in text!");
- }
- else {
- using (file = new System.IO.StreamWriter(@"D:\test1.txt", true)) {
- for (int i = 0; i <= amountOfWords; i++) {
- k = 1;
- unsafe {
- current.data[0] = Convert.ToByte(arrayOfWords[i].Length);
- string ex = arrayOfWords[i];/*
- for(int ii = 1; ii < ex.Length; ii++) {
- current.data[ii] = Convert.ToByte(ex[ii - 1]);
- }*/
- for(int ii = 0; ii < ex.Length; ii++) {
- Console.WriteLine(Convert.ToByte(ex[ii]));
- }
- for (int ii = 1; ii < 254; ii++) {
- for (int j = ii + 1; j < 255; j++) {
- if (current.data[j] < current.data[ii]) {
- byte temp = current.data[i];
- current.data[ii] = current.data[j];
- current.data[j] = temp;
- }
- }
- }
- }
- List<string> a = new List<string>();
- a.Add(arrayOfWords[i]);
- //dict.Add(current, a);
- if (dict.ContainsKey(current)==false) {
- dict.Add(current, a);
- }/*
- file.Write(arrayOfWords[i] + " ");
- for (int j = 0; j <= amountOfWords; j++) {
- if (((String.Equals(arrayOfWords[i], arrayOfWords[j]) == false)
- && (arrayOfWords[i].Length == arrayOfWords[j].Length))
- && ((String.Equals(string.Concat(arrayOfWords[i].ToLower().OrderBy(x => x).ToArray()), string.Concat(arrayOfWords[j].ToLower().OrderBy(x => x).ToArray())))
- )) {
- file.Write(arrayOfWords[j] + " ");
- k++;
- }
- }
- file.WriteLine();
- if (k > max) max = k;*/
- }
- }
- }
- Console.WriteLine("Maximal Amount of Anagramm Words = {0}", max);
- Console.ReadKey();
- // current.data[0] = calc_symbols_in_word(word);
- // for (int i = 1; i < 256; i++) {
- // current.data[i]=word[i-1]
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement