Advertisement
AvengersAssemble

09-10-13-WhileReview

Oct 10th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3.  
  4. namespace Practice
  5. {
  6.     class App
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.         }
  11.         static void Exercise26NumReversor()
  12.         {
  13.             int num = int.Parse(Console.ReadLine());
  14.             int reversedNum = 0;
  15.             int numForCalcs = num;
  16.             int i = 1;
  17.             while (numForCalcs != 0)
  18.             {
  19.                 numForCalcs /= 10;
  20.                 i *= 10;
  21.             }
  22.  
  23.             while (num != 0)
  24.             {
  25.                 i /= 10;
  26.                 reversedNum += num % (10) * i;
  27.                 num /= 10;
  28.             }
  29.             Console.WriteLine(reversedNum);
  30.         }
  31.         static void Exercise23BiggestCouple()
  32.         {
  33.             int count = 0, biggestSum, num1, num2;
  34.             num1 = int.Parse(Console.ReadLine());
  35.             num2 = int.Parse(Console.ReadLine());
  36.             biggestSum = num1 + num2;
  37.             while ((num1 % 2 == 0 && num2 % 2 == 0) || (num1 % 2 != 0 && num2 % 2 != 0))
  38.             {
  39.                 num1 = int.Parse(Console.ReadLine());
  40.                 num2 = int.Parse(Console.ReadLine());
  41.                 if ((num1 + num2) > biggestSum)
  42.                     biggestSum = num1 + num2;
  43.                 count++;
  44.             }
  45.             Console.WriteLine("Count: {0}\nBiggest sum: {1}", count, biggestSum);
  46.         }
  47.         static void Exercise24TomNJerry()
  48.         {
  49.             int tom = 10, jerry = 40, move, count = 0;
  50.             bool gameOver = false, playerIsTom = false;
  51.             string player = "Jerry";
  52.             Random rnd = new Random();
  53.             while (!gameOver)
  54.             {
  55.                 count++;
  56.                 playerIsTom = !playerIsTom;
  57.                 if (playerIsTom)
  58.                 {
  59.                     player = "Tom";
  60.                     move = rnd.Next(-5, 6);
  61.                     tom += move;
  62.                 }
  63.                 else
  64.                 {
  65.                     player = "Jerry";
  66.                     move = rnd.Next(-5, 6);
  67.                     jerry += move;
  68.                 }
  69.                 Console.WriteLine("Tom: {0}\nJerry: {1}\nLength: {2}\n", tom, jerry, count);
  70.                 if (tom > 50 || jerry > 50 || tom < 0 || jerry < 0)
  71.                 {
  72.                     Console.WriteLine("{0} lost the game!\n", player);
  73.                     gameOver = true;
  74.                 }
  75.                 if (tom == jerry)
  76.                 {
  77.                     Console.WriteLine("{0} won the game!\n", player);
  78.                     gameOver = true;
  79.                 }
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement