kisame1313

Untitled

Jul 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TestProgram
  4. {
  5.     class MyClass
  6.     {
  7.         static void Main ()
  8.         {
  9.             object obj = Animals ( 0, 0 );
  10.             Console.WriteLine ( obj );
  11.         }
  12.         public static object Animals ( int heads, int legs )
  13.         {
  14.             int cows, restOfHeads, cowLegs, chickLegs, chickens;
  15.  
  16.             if ( ( heads >= 0 & legs >= 0 ) & ( heads <= 1000 & legs <= 1000 )
  17.                 & ( legs % 2 == 0 ) & (heads != 0  ^ legs == 0) )
  18.             {
  19.                 if ( heads != 0 & legs != 0 )
  20.                 {
  21.                     if ( ( ( legs / heads ) <= 4 ) )
  22.                     {
  23.                         if ( legs % 4 == 0 )
  24.                         {
  25.                             cows = legs / 4;
  26.                             restOfHeads = heads - cows;
  27.                             cows -= restOfHeads;
  28.                             cowLegs = cows * 4;
  29.                             chickLegs = legs - cowLegs;
  30.                             chickens = chickLegs / 2;
  31.                         }
  32.                         else
  33.                         {
  34.                             cows = legs / 4;
  35.                             restOfHeads = heads - cows;
  36.                             cows = cows + 1 - restOfHeads;
  37.                             cowLegs = cows * 4;
  38.                             chickLegs = legs - cowLegs;
  39.                             chickens = chickLegs / 2;
  40.                         }
  41.                         return new int [2] { chickens, cows };
  42.                     }
  43.                     else
  44.                     { return "No solutions"; }
  45.                 }
  46.                 else
  47.                 { return new int [2] { 0, 0 }; }
  48.             }
  49.             else
  50.             { return "No solutions"; }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment