Задача Data Overflow
Judge ми дава 80/100 и не мога да разбера къде е проблема.
Мерси предварително!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
var firstNumber = int.Parse(Console.ReadLine());
var secondNumber = int.Parse(Console.ReadLine());
if (firstNumber>=secondNumber)
{
if (byte.MinValue<=firstNumber && byte.MaxValue>=firstNumber)
{
Console.WriteLine("bigger type: byte");
}
else if (ushort.MinValue<=firstNumber && ushort.MaxValue>=firstNumber)
{
Console.WriteLine("bigger type: ushort");
}
else if (uint.MinValue <= firstNumber && uint.MaxValue >= firstNumber)
{
Console.WriteLine("bigger type: uint");
}
else
{
Console.WriteLine("bigger type: ulong");
}
if (byte.MinValue <= secondNumber && byte.MaxValue >= secondNumber)
{
Console.WriteLine("smaller type: byte");
var puti = Math.Round(((double)firstNumber / byte.MaxValue));
Console.WriteLine("{0} can overflow byte {1} times", firstNumber, puti);
}
else if (ushort.MinValue <= secondNumber && ushort.MaxValue >= secondNumber)
{
Console.WriteLine("smaller type: ushort");
var puti = Math.Round(((double)firstNumber / ushort.MaxValue));
Console.WriteLine("{0} can overflow ushort {1} times", firstNumber, puti);
}
else if (uint.MinValue <= secondNumber && uint.MaxValue >= secondNumber)
{
Console.WriteLine("smaller type: uint");
var puti = Math.Round(((double)firstNumber / uint.MaxValue));
Console.WriteLine("{0} can overflow uint {1} times", firstNumber, puti);
}
else
{
Console.WriteLine("smaller type: ulong");
}
}
else
{
if (byte.MinValue <= secondNumber && byte.MaxValue >= secondNumber)
{
Console.WriteLine("bigger type: byte");
}
else if (ushort.MinValue <= secondNumber && ushort.MaxValue >= secondNumber)
{
Console.WriteLine("bigger type: ushort");
}
else if (uint.MinValue <= secondNumber && uint.MaxValue >= secondNumber)
{
Console.WriteLine("bigger type: uint");
}
else
{
Console.WriteLine("bigger type: ulong");
}
if (byte.MinValue <= firstNumber && byte.MaxValue >= firstNumber)
{
Console.WriteLine("smaller type: byte");
var puti = Math.Round(((double)secondNumber / byte.MaxValue));
Console.WriteLine("{0} can overflow byte {1} times", secondNumber, puti);
}
else if (ushort.MinValue <= firstNumber && ushort.MaxValue >= firstNumber)
{
Console.WriteLine("smaller type: ushort");
var puti = Math.Round(((double)secondNumber / ushort.MaxValue));
Console.WriteLine("{0} can overflow ushort {1} times", secondNumber, puti);
}
else if (uint.MinValue <= firstNumber && uint.MaxValue >= firstNumber)
{
Console.WriteLine("smaller type: uint");
var puti = Math.Round(((double)secondNumber / uint.MaxValue));
Console.WriteLine("{0} can overflow uint {1} times",secondNumber,puti);
}
else
{
Console.WriteLine("smaller type: ulong");
}
}
}
}
}
10.* Data Overflow
You will be given two numbers. Your task is to find the lowest one by value, find the numerical type it fits in from the following (byte, ushort, uint, ulong) and check how many times the greater one by value overflows the type of the smaller one (rounded to the nearest whole integer).
Examples
Input
Output
Explanation
100000
5
bigger type: uint
smaller type: byte
100000 can overflow byte 392 times
uint.MinValue ≤ 100000 ≤ uint.MaxValue
bigger type è uint
byte.MinValue ≤ 5 ≤ byte.MaxValue
smaller type è byte
100000 / byte.MaxValue = 392.1568 è 392
Input
Output
Input
Output
1200
2
bigger type: ushort
smaller type: byte
1200 can overflow byte 5 times
65535
131070
bigger type: uint
smaller type: ushort
131070 can overflow ushort 2 times
var firstNumber = int.Parse(Console.ReadLine());
var secondNumber = int.Parse(Console.ReadLine());
Това трябва да е decimal ->
var firstNumber = decimal.Parse(Console.ReadLine());
var secondNumber = decimal.Parse(Console.ReadLine());
и дава 90/100 в judge, след малко ще видя каква е последната грешка.
Не успях да намеря грешката, ако искаш погледни моя код и направи сравнение, надявам се да помогне.
https://gist.github.com/Warglaive/e6763885769db502b51da811c7a57150
успех.