反向范围ASCII算法方法

反向范围ASCII算法方法

本文介绍了C#反向范围ASCII算法方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
命名空间ConsoleApplication10
{
班级计划
{
公共静态无效的Main(string [] args)
{

Console.Write("Geben Sie bitte eine zuverschlüsselndeNummer ein:");
字符串newWords = Console.ReadLine();
字符串newWords2 = newWords.ToUpper();
Console.Write("Welchen AbstandmöchtenSie?");
int num1 = Convert.ToInt32(Console.ReadLine());
十进制选择= Convert.ToDecimal(num1);
Console.Write(WählenSieZählenvorwärts(1)oderrückwärtszählen(2)");
字符串opt = Console.ReadLine();
newWords2 = newWords2.Replace(Ö","OE");
newWords2 = newWords2.Replace(Ä","AE");
newWords2 = newWords2.Replace(Ü","UE");
newWords2 = newWords2.Replace(ß","SS");
newWords2 = newWords2.Replace(",");


Char [] arrayNewWords = newWords2.ToCharArray();


foreach(arrayNewWords中的char Newchar)
{
十进制a =转换(Newchar,choice,opt);
int b = Convert.ToInt32(a);
char c = Convert.ToChar(b);
字符串结果= c.ToString();
//Console.Write(value);
Console.Write(result);
}
Console.ReadLine();
}


公共静态小数转换(char Newchar,十进制选择,字符串opt)
{
十进制NewcharDecimal = Convert.ToInt32(Newchar);
十进制TotalTotal = 0;
如果(opt =="1")
{
十进制TotalValuePlus = NewcharDecimal +选择;
而((TotalValuePlus> 90)||(TotalValuePlus< 64))
{
如果(TotalValuePlus> = 90)
{
TotalValuePlus-= 90;

}
否则(TotalValuePlus< = 64)
{
TotalValuePlus + = 64;
}
}
如果((TotalValuePlus< = 90)&&(TotalValuePlus> = 65))
{
TotalTotal = TotalValuePlus;
//返回TotalTotal;
}
} 
否则,如果(opt =="2")
{
十进制TotalValueMinus = NewcharDecimal-选择;
而((TotalValueMinus> 90)||(TotalValueMinus< 64))
{
如果(TotalValueMinus> = 90)
{
TotalValueMinus + = 90;

}
否则(TotalValueMinus< = 64)
{
TotalValueMinus-= 64;
}
}
如果((TotalValueMinus< = 90)&&(TotalValueMinus> = 65))
{
TotalTotal = TotalValueMinus;
//返回TotalTotal;
}
}
返回TotalTotal;
} 
}
} 

粗体字是需要更改的IF ELSE方法.

我需要使用变量调节器将算法方法从65 = A转换为90 = Z的算法方法,该变量告诉程序必须在ascii表Table中倒数.

例如,当我计算A CHAR = 65 DEC并插入数字-3 DEC时,在我的头上,答案应为ascii表Table中的X CHAR = 88 DEC.

有人知道如何解决这个问题或该算法是什么?

非常感谢所有帮助.谢谢


解决方案


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication10
{
class Program
{
public static void Main(string[] args)
{
 
Console.Write("Geben Sie bitte eine zu verschlüsselnde Nummer ein: ");
string newWords = Console.ReadLine();
string newWords2 = newWords.ToUpper();
Console.Write("Welchen Abstand möchten Sie? ");
int num1 = Convert.ToInt32(Console.ReadLine());
decimal choice = Convert.ToDecimal(num1);
Console.Write("Wählen Sie Zählen vorwärts (1) oder rückwärts zählen (2) ");
string opt = Console.ReadLine();
newWords2 = newWords2.Replace("Ö", "OE");
newWords2 = newWords2.Replace("Ä", "AE");
newWords2 = newWords2.Replace("Ü", "UE");
newWords2 = newWords2.Replace("ß", "SS");
newWords2 = newWords2.Replace(" ", " ");
 
 
Char[] arrayNewWords = newWords2.ToCharArray();
 
 
foreach (char Newchar in arrayNewWords)
{
decimal a = Convertion(Newchar, choice, opt);
int b = Convert.ToInt32(a);
char c = Convert.ToChar(b);
string result = c.ToString();
// Console.Write(value);
Console.Write(result);
}
Console.ReadLine();
}
 
 
public static decimal Convertion(char Newchar, decimal choice, string opt)
{
decimal NewcharDecimal = Convert.ToInt32(Newchar);
decimal TotalTotal = 0;
if (opt == "1")
{
decimal TotalValuePlus = NewcharDecimal + choice;
while ((TotalValuePlus > 90) || (TotalValuePlus < 64))
{
if (TotalValuePlus >= 90)
{
TotalValuePlus -= 90;
 
}
else if (TotalValuePlus <= 64)
{
TotalValuePlus += 64;
}
}
if ((TotalValuePlus <= 90) && (TotalValuePlus >= 65))
{
TotalTotal = TotalValuePlus;
// return TotalTotal;
}
}
else if (opt == "2")
{
decimal TotalValueMinus = NewcharDecimal - choice;
while ((TotalValueMinus > 90) || (TotalValueMinus < 64))
{
if (TotalValueMinus >= 90)
{
TotalValueMinus += 90;
 
}
else if (TotalValueMinus <= 64)
{
TotalValueMinus -= 64;
}
}
if ((TotalValueMinus <= 90) && (TotalValueMinus >= 65))
{
TotalTotal = TotalValueMinus;
// return TotalTotal;
}
}
return TotalTotal;
}
}
}

the BOLD words is the IF ELSE method needed to be Change.

I need help for a Algorithm method reversing from the range 65 =A to 90 = Z with a variable adjuster which tells that the program must count backwards in the ascii table Table. 

for example in my head when i calculate A CHAR = 65 DEC and i insert the number - 3 DEC the answer should be X CHAR= 88 DEC in the ascii table Table. 

Does someone know how to figure this out or what is the algorithm for that?

All help is much appreciated.. THANK YOU


解决方案


这篇关于C#反向范围ASCII算法方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 16:00