Skip to content

Instantly share code, notes, and snippets.

@komkanit
Created September 22, 2015 13:47
Show Gist options
  • Save komkanit/b22e097811fe8ccd38a8 to your computer and use it in GitHub Desktop.
Save komkanit/b22e097811fe8ccd38a8 to your computer and use it in GitHub Desktop.
// =========== Edit Student Detail Here ============
// Program: countWords.cs
// RankId: 09
// Author: Komkanit Sujautra
// Id: 5810500412
// Group: 1/11
// Date: 17/9/2015
//===================================================
using System;
using System.IO;
class Count
{
public static void Main(string[] args)
{
if(args.Length == 0)
{
Console.WriteLine("Error: You must Input args");
return ;
}
char [] cut = {' ','.',';','=','{','}','(',')','\t','/','\n','\'','\"','\\','[',']'};
StreamReader inf = File.OpenText(args[0]);
string [] p = new string [300];
int [] count = new int [300];
int len = 0,j;
string line = inf.ReadLine();
while(line != null)
{
line = line.ToLower();
string [] str = line.Split(cut);
if(str.Length > 0)
{
foreach(string s in str)
{
if(s!="" && s[0]>= 'a' && s[0]<= 'z')
{
for(j=0 ; j < len ; j++)
{
if(p[j].Equals(s))
{
count[j]++;
break;
}
}
if(j == len)
{
p[len] = s;
count[len] = 1;
len++;
}
}
}
}
line = inf.ReadLine();
}
for(j=0 ; j<len ; j++)
{
Console.Write(p[j]+"="+count[j]+", ");
}
Console.WriteLine("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment