Created
July 7, 2009 05:48
-
-
Save dazza/141910 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace Fileter | |
{ | |
class HelloWorld | |
{ | |
int median(int a, int b, int c) | |
{ | |
int t; | |
if (a < b) | |
{ | |
t = b; | |
b = a; | |
a = t; | |
} | |
if (b < c) | |
{ | |
t = c; | |
c = b; | |
b = t; | |
} | |
if (a < b) | |
{ | |
t = b; | |
b = a; | |
a = t; | |
} | |
return b; | |
} | |
int[] MedianFileter(int[] data) | |
{ | |
int[] res = new int[data.Length]; | |
if (data.Length == 0) | |
{ | |
return res; | |
} | |
res[0] = data[0]; | |
res[data.Length - 1] = data[data.Length - 1]; | |
for (int i = 1; i < data.Length - 1; ++i ) | |
{ | |
res[i] = median(data[i - 1], data[i], data[i + 1]); | |
} | |
return res; | |
} | |
class Tester | |
{ | |
static void Main() | |
{ | |
string str; | |
str = Console.ReadLine(); | |
while (!string.IsNullOrEmpty(str)) | |
{ | |
str = str.Remove(0, 1); | |
str = str.Remove(str.Length - 1, 1); | |
string[] value = str.Split(','); | |
int[] intval = new int[value.Length]; | |
for (int i = 0; i < value.Length; ++i) | |
{ | |
bool re = int.TryParse(value[i], out intval[i]); | |
Console.WriteLine(intval[i]); | |
} | |
HelloWorld hw = new HelloWorld(); | |
int[] res = hw.MedianFileter(intval); | |
str = Console.ReadLine(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment