我的程序是将字符串解码为数字并对此数字执行一些操作。
以下程序适用于小字符串。处理大段落的更好方法是什么(在这种情况下作为输入)?!
public static void Main()
{
///<summary>Encoded String- Checking divisibility</summary>
Console.WriteLine("Enter Lowercase Latin letters ( 'a'-'i' )");
string originalString = Convert.ToString(Console.ReadLine());
bool chkValue = Regex.IsMatch(originalString, @"^[a-i]+$");
if(!chkValue)
{
return;
}
char[] originalchars = originalString.ToCharArray();
long decodedNumber=0;
StringBuilder decoded = new StringBuilder();
//int stringLength = originalString.Length;
for (int i = 0; i < originalchars.Length; i++)
{
decoded.Append(Convert.ToInt32(originalchars[i] - 96));
}
Console.WriteLine(decoded);
string decodedString = decoded.ToString();
bool parseResult = long.TryParse(decodedString ,out decodedNumber);
if (parseResult == true)
{
if (decodedNumber % 6 == 0)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
Console.ReadLine();
}
答案 0 :(得分:0)
史蒂夫提到, BigInteger 解决了我的问题。