矩阵

using System;
using System.Collections.Generic;

namespace 测试题2
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("请输入电话号码!");
            string str = Console.ReadLine();

            List<int> myNumArray = new List<int>();

            for (int counter = 0; counter < str.Length; counter++)
            {
                myNumArray.Add(int.Parse(str[counter].ToString()));
            }

            int CountHe = 0;
            int InitTrasform = 5;
            for (int i = 0; i < myNumArray.Count; i++)
            {
                CountHe = CalculateCount(InitTrasform, myNumArray[i]) + CountHe;
                InitTrasform = myNumArray[i];
            }
            Console.WriteLine(CountHe);
        }
        // 计算步数
        static int CalculateCount(int before, int after)
        {
            int[,] arrData = new int[12, 3] {
                {0,0,1},{ 0,1,2}, { 0, 2,3 },  { 1, 0,4 }, { 1,1,5 }, { 1, 2,6 }, { 2, 0 ,7}, { 2, 1,8 }, { 2,2,9 }, { 3, 0 ,10}, {3, 1,0}, { 3, 2,11 }
            };
            List<int> num_before = new List<int>();
            List<int> num_after = new List<int>();
            num_before = GetArrDataPos(arrData, before);
            num_after = GetArrDataPos(arrData, after);
            int numHe = 0;         
            for (int i = 0; i < num_before.Count; i++)
            {
                numHe = Math.Abs(num_before[i] - num_after[i]) + numHe;
            }            
            return numHe;
        }

        // 获取位置数组
        static List<int> GetArrDataPos(int[,] arrData, int pos)
        {
            int len = arrData.GetLength(1);
            List<int> numdata = new List<int>();
            for (int i = 0; i < arrData.GetLength(0); i++)
            {
                if (arrData[i, len - 1] == pos)
                {                   
                    numdata.Add(arrData[i, 0]);
                    numdata.Add(arrData[i, 1]);
                }
            }
            return numdata;
        }       
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值