在SPOJ上运行以下代码时,我收到运行时错误(NZEC).如果你们中的任何人愿意指出发生了什么,我将非常感激.
//0<=A<=B<=10^18, 1<=N<=10^18
using System;
class any
{
static void Main()
{
long t = long.Parse(Console.ReadLine());
ulong a, b, n;
for(long k = 0; k < t; k++)
{
string[]s = Console.ReadLine().Split(' ');
a = ulong.Parse(s[0]);
b = ulong.Parse(s[1]);
n = ulong.Parse(s[2]);
Console.WriteLine(diviEntre2(a, b, n));
}
}
static ulong diviEntre2(ulong f, ulong c, ulong n)
{
ulong k, s, m;
if (f == c && c % n == 0 && f != 0) k = c/n;
else
{
s …Run Code Online (Sandbox Code Playgroud) 让我们直截了当.我做了下面的代码来乘以两个数字,它正在"吃掉"我的零!对于不涉及产品(p)等于零的情况,似乎工作正常.在样本情况下,它只是打印"5"而不是所需的"500".如果有人愿意解释发生了什么,我真的很感激.:)
using System;
class Program
{
static void Main()
{
Console.WriteLine(smallNumBigNumProduct("5", "100"));
}
static string smallNumBigNumProduct(string s, string b)
{
int l = s.Length;
int f = int.Parse(s); // factor
int c = 0; // carry
string r = ""; // result
int p; // product
while(l-- > 0)
{
p = (Convert.ToInt32(b[l]) - 48) * f;
p += c;
if (p > 9)
{
r = Convert.ToString(p % 10) + r;
c = p / 10;
}
else
r …Run Code Online (Sandbox Code Playgroud)