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

Suthish NairRank #92 · 22.8K reputationPosted Apr 8, 2011, 8:54 AM EDT
Sin Yee142 reputationPosted Apr 8, 2011, 9:43 AM EDT
Andrew FensterRank #983 · 2K reputationPosted Apr 8, 2011, 9:49 AM EDT
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 Yee142 reputationPosted Apr 8, 2011, 9:57 AM EDT
Andrew FensterRank #983 · 2K reputationPosted Apr 8, 2011, 10:07 AM EDT
Sin Yee142 reputationPosted Apr 10, 2011, 6:57 AM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Apr 10, 2011, 7:48 AM EDT