zoukankan      html  css  js  c++  java
  • 使用程序调试输出窗口

    程序输出窗口用来对程序运行过程进行监控。

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Diagnostics;
    namespace a
    {
    	class Program
    	{
    		static void Main(string[] args)
    		{
    			int[] textArray={4,7,4,2,7,3,7,8,3,9,1,9};
    			int[] maxValIndices;
    			int maxVal= Maxima(textArray,out maxValIndices);
    			Console.WriteLine("Maximum value {0} found at element indices:",maxVal);
    			foreach(int index in maxValIndices)
    			{
    				Console.WriteLine(index);
    			}
    			Console.ReadKey();
    		}
    		static int Maxima(int[] integers,out int[] indices)
    		{
    			Debug.WriteLine("Maximum value search started.");
    			indices=new int[1];
    			int maxVal=integers[0];
    			indices[0]=0;
    			int count=1;
    			Debug.WriteLine("Maximum value initialized to"+maxVal+",at element index 0.");
    			for (int i=1;i<integers.Length;i++)
    			{
    				Debug.WriteLine("Now looking at element at index"+i+".");
    				if(integers[i]>maxVal)
    				{
    					maxVal=integers[i];
    					count=1;
    					indices=new int[1];
    					indices[0]=i;
    					Debug.WriteLine("New maximum found. New value is"+maxVal+",at element index"+i+".");
    				}
    				else
    				{
    					if(integers[i]==maxVal)
    					{
    						count++;
    						int[] oldIndices=indices;
    						indices=new int[count];
    						oldIndices.CopyTo(indices,0);
    						Debug.WriteLine("Duplicate maximum found at element index"+i+".");
    					}
    				}
    			}
    			Trace.WriteLine("Maximum value "+maxVal+"found,with"+count+"occurences.");
    			Debug.WriteLine("Maximum value search completed.");
    			return maxVal;
    		}
    	}
    }
  • 相关阅读:
    《入门经典》——6.25
    《入门经典》——6.24
    hdu4417
    poj2104(划分树模板)
    D. 实验室传染病
    poj2069
    poj1379
    hdu5950
    poj3417
    LCA——求解最近公共祖先
  • 原文地址:https://www.cnblogs.com/bimgoo/p/2470544.html
Copyright © 2011-2022 走看看