All pastes #942177 Raw Edit

Mine

public text v1 · immutable
·published 2008-03-14 09:39 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;

namespace AaronsChallange
{
    class Program
    {
        /// <summary>
        /// Will we be using Random Numbers?
        /// </summary>
        /// <returns>TRUE OR FALSE LUL</returns>
        static bool UseRandomNumbers() {
            while ( true ) {
                Console.WriteLine( "Use Random Numbers? y/n" );
                string t = Console.ReadLine().ToLower();
                if ( t == "y" )
                    return true;
                else if ( t == "n" )
                    return false;
            }
        }

        /// <summary>
        /// Lists the content in an INTEGER ARRAY
        /// </summary>
        /// <param name="intray">And array of integers.</param>
        static void ListIntArray( int[] intray, bool reverse ) {

            int[] r = new int[10];

            if ( reverse ) {
                for ( int i = 0; i < 10; i++ ) {
                    r[i] = intray[9 - i];
                }
                //Reversitization
            }
            else
                r = intray;

            for ( int x = 0; x < 10; x++ ) {
                if ( x == 0 )
                    Console.Write( "[ " + r[x] + ", " );
                else if ( x == 9 )
                    Console.Write( r[x] + " ]\n" );
                else
                    Console.Write( r[x] + ", " );
            }

        }

        /// <summary>
        /// The main diggity shiggity
        /// </summary>
        /// <param name="args"></param>
        static void Main( string[] args ) {
            Console.WriteLine( "AARON > FISH > ORANGEPNUT" );
            int[] numbers = new int[10];
            
            if ( UseRandomNumbers() ) {
                Random r = new Random();
                for ( int i = 0; i < 10; i++ ) {
                    numbers[i] = r.Next( 0, 10 );
                }
            }
            else {
                int i = 0;
                Console.WriteLine( "Enter 10 numbers between 0-10: " );
                while ( i != 10 ) {
                    Console.Write( "Number[" + (i+1) + "]: " );
                    string t = Console.ReadLine().ToLower();
                    int x;
                    
                    try {
                        x = int.Parse( t );
                    }
                    catch ( FormatException ) {
                        continue;
                    }

                    if ( x < 0 || x > 10 )
                        continue;

                    numbers[i] = x;
                    i++;
                }
            }

            ShowArray( numbers );

            Console.WriteLine( "\ncan has FIND & REPLACE TIME nao?");
            Console.Write( "Search for this number: " );
            int s = GetInt();
            Console.Write( "Replace With this Number:" );
            int n = GetInt();
            Console.WriteLine();

            Console.WriteLine( "Number of Instances Replaced: " + CountInstancesOfANumberInAnArrayAndReturnTheCountNumberAsAnIntegerAndAlsoChangeTheInputArrayAndAaronIsAGoodTeacher( out numbers, numbers, s, n ) );
            ShowArray( numbers );

            Console.WriteLine( "Press any key to terminate process." ); //^_^
            Console.ReadLine();

        }

        /// <summary>
        /// Shows an array both reversed and normally.
        /// </summary>
        /// <param name="i">Number to show.</param>
        static void ShowArray( int[] i ) {
            Console.WriteLine( "Your Numbers:" );
            ListIntArray( i, false );
            Console.WriteLine( "Your Numbers (REVERSED):" );
            ListIntArray( i, true );
        }

        /// <summary>
        /// Gets an int and makes sure it's between 0-10.
        /// </summary>
        /// <returns>User's Input as an int.</returns>
        static int GetInt() {
            int i = 0;
            while ( true ) {
                try {
                    i = int.Parse(Console.ReadLine());
                }
                catch ( FormatException ) {
                    continue;
                }
                if ( i < 0 || i > 10 )
                    continue;

                break;
            }
            return i;
        }

        /// <summary>
        /// Counts the number of instances in this array and returns it.
        /// Replaces a with b.
        /// </summary>
        /// <param name="ia">Array to do the lookup & change.</param>
        /// <param name="iaa">copy of the array.</param>
        /// <param name="a">Search number.</param>
        /// <param name="b">Replace number.</param>
        /// <returns></returns>
        static int CountInstancesOfANumberInAnArrayAndReturnTheCountNumberAsAnIntegerAndAlsoChangeTheInputArrayAndAaronIsAGoodTeacher( out int[] ia, int[] iaa, int a, int b ) {
            int c = 0; //Count
            int[] t = new int[10];
            ia = iaa;
            for ( int i = 0; i < ia.Length; i++ ) {
                if ( ia[i] == a ) {
                    c++;
                    iaa[i] = b;
                }
                else {
                    iaa[i] = ia[i];
                }
            }

            ia = iaa;
            return c;
        }
    }
}