Skip to content

Instantly share code, notes, and snippets.

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