Simple Loops 12. Equal Pairs
Здравейте,
Може ли някой да ми помогне?
Получавам по-малко точки за задачата, а мисля че JUDGE има грешка:
при вход:
7
34
-33
52
12
-32
32
23
41
7
25
34
23
124
21
Judje иска изход 88, а аз мисля че е 145/Сумата на последните две числа е 124+21=145, а на -32+32=0)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Equal_Pairs
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
double sumPairs = 0;
double sumPairsMin = 99999999999999.0;
double sumPairsMax = -99999999999999.0;
int count = 0;
for (int i = 1; i <= n; i++)
{
double numberOdd = double.Parse(Console.ReadLine());
double numberEven = double.Parse(Console.ReadLine());
sumPairs = sumPairs + numberOdd + numberEven;
sumPairsMax = Math.Max(sumPairsMax, numberOdd + numberEven);
sumPairsMin = Math.Min(sumPairsMin, numberEven + numberOdd);
if (sumPairs/i==numberEven+numberOdd)
{
count += 1;
}
}
if (count==n)
{
Console.WriteLine($"Yes, value={sumPairsMax}");
}
else
{
Console.WriteLine($"No, maxdiff={sumPairsMax-sumPairsMin}");
}
}
}
}
И как го направи?
Защото аз го направих с малко по различна логика?
http://pastebin.com/j9UV91Ju
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Equal_Pairs
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
double sumPairs = 0;
double sumPairsMin = 99999999999999.0;
double sumPairsMax = -99999999999999.0;
double sum1 = 0.0;
double sum2 = 0.0;
double diff = 0.0;
int count = 0;
for (int i = 1; i <= n; i++)
{
double numberOdd = double.Parse(Console.ReadLine());
double numberEven = double.Parse(Console.ReadLine());
if (i%2==1)
{
sum1 = numberEven + numberOdd;
}
else
{
sum2 = numberOdd + numberEven;
}
diff = Math.Max(diff, Math.Abs(sum1 - sum2));
sumPairs = sumPairs + numberOdd + numberEven;
sumPairsMax = Math.Max(sumPairsMax, numberOdd + numberEven);
sumPairsMin = Math.Min(sumPairsMin, numberEven + numberOdd);
if (sumPairs/i==numberEven+numberOdd)
{
count += 1;
}
}
if (count==n)
{
Console.WriteLine($"Yes, value={sumPairsMax}");
}
else if(n>2)
{
Console.WriteLine($"No, maxdiff={diff}");
}
else
{
Console.WriteLine($"No, maxdiff={sumPairsMax - sumPairsMin}");
}
}
}
}
Това е решението ми,
Ако имаш въпроси пиши