# 今天遇到的一个算发

525人阅读 评论(0)

encode:

decode:解码

encode代码部分：
strOld = this.textBox1.Text;
strLeng = strOld.Length;
char[] a=strOld.ToCharArray();
for(int i=0;i<strLeng;i++)
{

intNow=a[i];
if(intNow<intZero)
{
strNew+=a[i]+"_";
}
if((intNow>intZero)&&(intNow<intNight))
{
if (i == strLeng-1)
{
strNew += a[i] ;
}
else
{
int ab = Convert.ToInt32(a[i].ToString());
//MessageBox.Show(ab.ToString());
for (int j = 0; j < ab + 1; j++)
{
strNew += a[i + 1];
}
strNew += "_";
}
}
if(intNow>intNight)
{
if (intNow != intheng)
{
strNew += a[i] + "_";
}
else
{
strNew += "//UL";
}
}

}
this.textBox3.Text=strNew;

decode:

string enStrOld = this.textBox3.Text.Replace("//UL","_");
string enStrNew = "";
char[] ena = enStrOld.ToCharArray();
int[] enb=new int[50];
int enbindex=0;
int intLength = enStrOld.Length;
for (int eni = 0; eni < intLength; eni++)
{
if (ena[eni] == intheng)
{
enb[enbindex] = eni;
enbindex++;
}

}
for (int k = 0; k < enbindex; k++)
{
int ent = enb[k];
if (ena[ent - 1] == ena[ent - 2])
{
if (k == 0)
{
enStrNew += enb[k] - 1;
}
else
{
int test = enb[k] - enb[k - 1] - 2;
if (test > 0)
{
enStrNew += test;
}
}
}
else
{

int encount = enb[k] - enb[k - 1] - 1;
if (encount == 0)
{
enStrNew += "_";
}
else
{
for (int entt = 0; entt < encount; entt++)
{
enStrNew += ena[enb[k - 1] + 1 + entt];
}
}
}
}
enStrNew += ena[enStrOld.LastIndexOf("_") + 1];
this.textBox2.Text = enStrNew;

private int intZero = (char)'0';
private int intNight = (char)'9';
private int intheng = (char)'_';
private string strOld = "";
private int strLeng;
private int intNow;
private string strNew="";

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：100283次
• 积分：1483
• 等级：
• 排名：千里之外
• 原创：52篇
• 转载：20篇
• 译文：0篇
• 评论：5条
文章分类
评论排行
最新评论
收藏宝典