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;
}
}
}