Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TestProgram
- {
- class MyClass
- {
- static void Main ()
- {
- object obj = Animals ( 0, 0 );
- Console.WriteLine ( obj );
- }
- public static object Animals ( int heads, int legs )
- {
- int cows, restOfHeads, cowLegs, chickLegs, chickens;
- if ( ( heads >= 0 & legs >= 0 ) & ( heads <= 1000 & legs <= 1000 )
- & ( legs % 2 == 0 ) & (heads != 0 ^ legs == 0) )
- {
- if ( heads != 0 & legs != 0 )
- {
- if ( ( ( legs / heads ) <= 4 ) )
- {
- if ( legs % 4 == 0 )
- {
- cows = legs / 4;
- restOfHeads = heads - cows;
- cows -= restOfHeads;
- cowLegs = cows * 4;
- chickLegs = legs - cowLegs;
- chickens = chickLegs / 2;
- }
- else
- {
- cows = legs / 4;
- restOfHeads = heads - cows;
- cows = cows + 1 - restOfHeads;
- cowLegs = cows * 4;
- chickLegs = legs - cowLegs;
- chickens = chickLegs / 2;
- }
- return new int [2] { chickens, cows };
- }
- else
- { return "No solutions"; }
- }
- else
- { return new int [2] { 0, 0 }; }
- }
- else
- { return "No solutions"; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment