My favorites
▼
|
Sign in
hefdoeshwk
Code exercises for the blog Hef Does Homework.
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
topcoder
/
Srm145
/
Div2
/
ImageDithering.cs
r24
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;
}
}
}
Show details
Hide details
Change log
r5
by jonathan.hefner on Jun 22, 2008
Diff
Sync
Go to:
/trunk/eopl2/scheme/1.26.scm
/trunk/eopl2/scheme/1.31.scm
/trunk/eopl2/scheme/1.32.scm
/trunk/eopl2/scheme/1.33.scm
/trunk/shiftsrt
/trunk/shiftsrt/perl
/trunk/shiftsrt/perl/shiftsrt.pl
/trunk/shiftsrt/python
/trunk/shiftsrt/python/shiftsrt.py
/trunk/topcoder
/trunk/topcoder/Properties
...coder/Properties/AssemblyInfo.cs
/trunk/topcoder/Srm144
/trunk/topcoder/Srm144/Div1
...nk/topcoder/Srm144/Div1/1100.doc
/trunk/topcoder/Srm144/Div1/300.txt
/trunk/topcoder/Srm144/Div1/550.doc
.../topcoder/Srm144/Div1/Lottery.cs
...coder/Srm144/Div1/LotteryTest.cs
/trunk/topcoder/Srm144/Div2
...nk/topcoder/Srm144/Div2/1100.doc
/trunk/topcoder/Srm144/Div2/200.doc
/trunk/topcoder/Srm144/Div2/550.doc
...pcoder/Srm144/Div2/BinaryCode.cs
...er/Srm144/Div2/BinaryCodeTest.cs
...coder/Srm144/Div2/PowerOutage.cs
...r/Srm144/Div2/PowerOutageTest.cs
/trunk/topcoder/Srm144/Div2/Time.cs
...topcoder/Srm144/Div2/TimeTest.cs
/trunk/topcoder/Srm145
/trunk/topcoder/Srm145/Div2
...nk/topcoder/Srm145/Div2/1100.doc
/trunk/topcoder/Srm145/Div2/250.doc
/trunk/topcoder/Srm145/Div2/500.doc
...r/Srm145/Div2/ExerciseMachine.cs
...m145/Div2/ExerciseMachineTest.cs
...er/Srm145/Div2/ImageDithering.cs
...rm145/Div2/ImageDitheringTest.cs
...er/Srm145/Div2/VendingMachine.cs
...rm145/Div2/VendingMachineTest.cs
/trunk/topcoder/Srm146
/trunk/topcoder/Srm146/Div2
...nk/topcoder/Srm146/Div2/1000.doc
/trunk/topcoder/Srm146/Div2/250.doc
/trunk/topcoder/Srm146/Div2/500.doc
...er/Srm146/Div2/BridgeCrossing.cs
...rm146/Div2/BridgeCrossingTest.cs
...r/Srm146/Div2/RectangularGrid.cs
...m146/Div2/RectangularGridTest.cs
...oder/Srm146/Div2/YahtzeeScore.cs
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1088 bytes, 37 lines
View raw file
Powered by
Google Project Hosting