using
System; namespace
ConsoleApplication1 { class Program { static void Main(string[ ] args) { // vars const int N = 20; int[ ] large = new int[N]; int[ ] small = new int[5]; int i; // initialize for ( i = 0 ; i < 5 ; ++i ) {
small[ i] = i + 1; Console.Write(small[ i]); } Console.WriteLine(); for ( i = 0 ; i < N ; ++i ) {
large[i ] = i % 7; Console.Write(large[ i]); } // do the counting Console.WriteLine("\nsmall
was fount {0} times in large", HowManyTimesIn(N, large, small)); }
static int
HowManyTimesIn(int N, int[
] large, int[ ] small) { int count = 0; for ( int k = 0 ; k
<= N - 5 ; ++k ) { int l = 0; while ( l < 5 && small[ l] == large[k + l]
)
++l; if ( l == 5 ) ++count; } return count; } } } |