Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 3 KB
using System;
using System.Collections.Generic;
namespace FejVagyIras
{
class Program
{
private bool HEAD = false;
private bool TAIL = true;
private int n = 25;
private bool[] data = new bool[50];
private List<byte> maxWidth = new List<byte>();
private List<int> futamszam = new List<int>();
private String pattern;
private int patternFound = 0;
public void initPattern()
{
Console.Write("Kérem a mintát: ");
pattern = Console.ReadLine();
}
public void handlePattern()
{
int pos = 0;
bool cool = true;
while( (pos + pattern.Length) <= n )
{
cool = true;
for( int i=0; i<pattern.Length; i++ )
{
if( !isEqual(pattern[i], data[i+pos]) )
{
pos++;
cool = false;
break;
}
}
if( cool ) {
patternFound++;
break;
}
}
}
public void endPattern()
{
Console.WriteLine("Előfordulások száma: " + patternFound);
}
public void initAvgWidth()
{
Console.WriteLine("Számolom a maximális átlagos FEJ-sorozatok hosszát...");
}
public void handleAvgWidth()
{
byte max = 0;
byte v = 0;
for (int i=0; i<n; i++ )
{
if( data[i] == HEAD ) {
v++;
if( v > max ) max = v;
} else v = 0;
}
maxWidth.Add( max );
}
public void endAvgWidth()
{
long sum = 0;
for( int i=0; i<maxWidth.Count; i++ )
{
sum += maxWidth[i];
}
Console.WriteLine("Átlag: "+((double)sum/(double)maxWidth.Count));
}
public void initChanges()
{
Console.WriteLine("Átlagos futamszám számolása...");
}
public void handleChanges()
{
bool prevState = data[0];
int futamszam = 1;
for( int i=1; i<n; i++ )
{
if( prevState != data[i] ) {
futamszam++;
prevState = data[i];
}
}
this.futamszam.Add(futamszam);
}
public void endChanges()
{
long sum = 0;
for( int i=0; i<futamszam.Count; i++ )
{
sum += futamszam[i];
}
Console.WriteLine("Eredmény: "+((double)sum/(double)futamszam.Count));
}
public bool isEqual( char c, bool b )
{
if( (b && c=='I') || (!b && c=='F') ) return true;
return false;
}
public void handle( )
{
handlePattern();
handleAvgWidth();
handleChanges();
}
public void recursive( int i )
{
if( i == n )
{
handle();
} else {
data[i] = true;
recursive( i+1 );
data[i] = false;
recursive( i+1 );
}
}
public static void Main(string[] args)
{
Program p = new Program();
p.initPattern();
p.initAvgWidth();
p.initChanges();
p.recursive( 0 );
p.endPattern();
p.endAvgWidth();
p.endChanges();
Console.ReadLine();
}
}
}