Created
September 22, 2015 13:47
-
-
Save komkanit/b22e097811fe8ccd38a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// =========== 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