hey..i got two text file and i need to total up the occurrance in tht two files..
For example:
my first file:
1 2 3 4
1 3 4
my second file:
1 3 4
2 5
After total up the item in this two file:
1: 3
2: 2
3: 3
4:3
using Dictionary <> to do this..hope someone will help me...thank you
Loading
VulpesPosted Apr 10, 2011, 11:48 AM
Sin YeePosted Apr 10, 2011, 10:57 AM
File 1 got two lines :
1 2 3 4
1 3 4
File 2 got two lines:
1 3 4
2 5
i need to count total value for each items in those two files
1:3
2:2
3:3
4:3
5:1
and sort in descending order.
Andrew FensterPosted Apr 8, 2011, 2:07 PM
Sin YeePosted Apr 8, 2011, 1:57 PM
Andrew FensterPosted Apr 8, 2011, 1:49 PM
Dictionary
Each time you count an object:
if (counter.ContainsKey(key)
counter[key]++;
else
counter.Add(key, 1);
To sort in descending order:
var items = from key in counter.Keys
orderby counter[key] descending
select key;
foreach (int key in items)
Console.WriteLine("{0}: {1}", key, counter[key]);
Sin YeePosted Apr 8, 2011, 1:43 PM
Suthish NairPosted Apr 8, 2011, 12:54 PM