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;
- namespace filing
- {
- public struct alphabet
- {
- public char value;
- public int frequency;
- }
- class Program
- {
- static void Main(string[] args)
- {
- string s = Console.ReadLine();
- alphabet[] word = new alphabet[s.Length];
- System.IO.FileStream fs = new System.IO.FileStream("C:\\Users\\ABD\\Desktop\\input.txt", System.IO.FileMode.OpenOrCreate);
- System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
- bw.Write(s);
- bw.Close();
- System.IO.FileStream fs1 = new System.IO.FileStream("C:\\Users\\ABD\\Desktop\\input.txt", System.IO.FileMode.Open);
- System.IO.BinaryReader br = new System.IO.BinaryReader(fs1);
- br.ReadChar();
- string newS = "";
- int j = 0;
- for (int i = 0; i < s.Length; i++)
- {
- char temp = br.ReadChar();
- if (contain(newS, temp) > -1)
- { word[contain(newS, temp)].frequency++;
- }
- else
- {
- word[j].value = temp;
- word[j].frequency = 1;
- newS += temp;
- j++;
- }
- }
- for(int i = 0; i<j; i++)
- {
- Console.WriteLine("Value = {0}\tFrequency = {1}", word[i].value, word[i].frequency);
- }
- }
- public static int contain(string s, char c)
- {
- int pos = -1;
- for(int i = 0; i < s.Length; i++)
- {
- if (s[i] == c)
- pos = i;
- }
- return pos;
- }
- }
- }
Add Comment
Please, Sign In to add comment