My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;

namespace Hef.TopCoder.Srm145.Div2
{
public class ImageDithering
{
public int count(string dithered, string[] screen)
{
// setup
List<char> diths = new List<char>(dithered.ToCharArray());
char[][] grid = new char[screen.Length][];
for (int i = 0; i < screen.Length; i += 1)
grid[i] = screen[i].ToCharArray();

// find dithering colors next to each other
int result = 0;
for (int i = 0; i < grid.Length; i += 1)
{
for (int j = 0; j < grid[i].Length; j += 1)
{
if (diths.Contains(grid[i][j]) && (
(i > 0 && diths.Contains(grid[i - 1][j])) // above
|| (i < grid.Length - 1 && diths.Contains(grid[i + 1][j])) // below
|| (j > 0 && diths.Contains(grid[i][j - 1])) // left
|| (j < grid[i].Length - 1 && diths.Contains(grid[i][j + 1])) // right
))
{
result += 1;
}
}
}

return result;
}
}
}

Change log

r5 by jonathan.hefner on Jun 22, 2008   Diff
Sync
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1088 bytes, 37 lines
Powered by Google Project Hosting