Професионална програма
Loading...
+ Нов въпрос
ddrajko avatar ddrajko 5 Точки

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}");
            }
        }
    }
}

 

Тагове:
0
Programming Basics
ddrajko avatar ddrajko 5 Точки

Справих се!

Условието е за максимална разлика между 2 последователни двойки!

0
ramsess avatar ramsess 1 Точки

И как го направи?

Защото аз го направих с малко по различна логика?

http://pastebin.com/j9UV91Ju

0
15/02/2017 12:39:35
ddrajko avatar ddrajko 5 Точки

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}");
            }
        }
    }
}

 

0
ddrajko avatar ddrajko 5 Точки

Това е решението ми,

Ако имаш въпроси пиши

0
Destinote avatar Destinote 5 Точки

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _12.PairOfNumbers
{
    class PairOfNumbers
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("The exercise is: To enter N pairs of numbers, and decide if they are equal or not. if not, find the maximum difference, between the biggest pair and lowest. ");
            //Console.WriteLine("Enter the desired number of pairs:");
            int NumberOfLoops = int.Parse(Console.ReadLine());
            double Sum = 0.0;
            double LastSum = 0.0;
            double Difference = 0.0;

            for (int Index = 0; Index < NumberOfLoops; Index++)
            {
                double Number1 = double.Parse(Console.ReadLine());
                double Number2 = double.Parse(Console.ReadLine());
                Sum = Number1 + Number2;

                if (Index > 0)
                {
                    Difference = LastSum - Sum;
                    Difference = Math.Abs(Difference);
                }

                LastSum = Sum;
            }

            if (Difference == 0 )
            {
                Console.WriteLine($"Yes, value={Sum}");
            }
            else if (Difference != 0)
            {
                Console.WriteLine($"No maxdiff={Difference}");
            }
        }
    }
}

 

Ето го и моя код. Колкото се може по-упростен. 

0
Sim0o0na avatar Sim0o0na Trainer 566 Точки

Здравейте,

За да бъдат по-лесно четими темите във форума, моля спазвайте неговите правила.

 

0