Advertisement
DennyGD

KaspichaniaBoats

Jan 17th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.78 KB | None | 0 0
  1. Problem 4 - Kaspichania Boats
  2. The country of Kaspichania was once one of the greatest empires in the known universe. However after fierce battles with the neighboring countries of Javaland and CSharpia the armed forces of Kaspichania were dwindling. Then all of a sudden they decided they needed a change of strategy – they would start building a huge naval fleet. They hired boat architects and wood and material providers. But they needed a factory to manufacture them. This is where you come in.
  3. Your task is to create the boats needed by the country of Kaspichania to win their next battle. You will be given the size of the desired bottom (N) of the boat and your task is to build it. The entire width of the boat must be N * 2 + 1 and the height: 6 + ((N - 3) / 2) * 3. The boats have sails with a height 2/3 of the entire height of the boat. The base of the boat is the other 1/3 of the height. The boats also have a supporting beam that goes through the entire height of the boat.
  4. Input
  5. The input data should be read from the console.
  6. You have an integer number N - the size of the bottom of the boat.
  7. The input data will always be valid and in the format described. There is no need to check it explicitly.
  8. Output
  9. The output should be printed on the console.
  10. Use the “*for the lines and “.(dot) for the rest.
  11. Constraints
  12. • N will always be a positive number between 2 and 39 inclusive.
  13. • Allowed working time for your program: 0.1 seconds.
  14. • Allowed memory: 16 MB.
  15.  
  16. using System;
  17.  
  18. namespace KaspichaniaBoats
  19. {
  20.     class KaspichaniaBoats
  21.     {
  22.         static void Main()
  23.         {
  24.             int bottomN = Int32.Parse(Console.ReadLine());
  25.             double N = Convert.ToDouble(bottomN);
  26.             int width = (bottomN * 2) + 1;
  27.             double height = 6 + ((N - 3) / 2) * 3;
  28.             double baseB = (1D / 3D) * height;
  29.  
  30.             int dotsEnds = bottomN;
  31.             int dotsMiddle = 1;
  32.  
  33.             for (int i = 1; i <= bottomN; i++)
  34.             {
  35.                 if (i == 1)
  36.                 {
  37.                     Console.Write(new string('.', dotsEnds));
  38.                     Console.Write('*');
  39.                     Console.WriteLine(new string('.', dotsEnds));
  40.                 }
  41.                 else if (i == 2)
  42.                 {
  43.                     Console.Write(new string('.', dotsEnds));
  44.                     Console.Write(new string('*', 3));
  45.                     Console.WriteLine(new string('.', dotsEnds));
  46.                 }
  47.                 else
  48.                 {
  49.                     Console.Write(new string('.', dotsEnds));
  50.                     Console.Write('*');
  51.                     Console.Write(new string('.', dotsMiddle));
  52.                     Console.Write('*');
  53.                     Console.Write(new string('.', dotsMiddle));
  54.                     Console.Write('*');
  55.                     Console.WriteLine(new string('.', dotsEnds));
  56.                     dotsMiddle++;
  57.                 }
  58.                 dotsEnds--;
  59.             }
  60.  
  61.             Console.WriteLine(new string('*', width));
  62.  
  63.             dotsEnds = 1;
  64.             dotsMiddle = (width - 5) / 2;
  65.  
  66.             for (int i = 1; i < baseB; i++)
  67.             {
  68.                 Console.Write(new string('.', dotsEnds));
  69.                 Console.Write('*');
  70.                 Console.Write(new string('.', dotsMiddle));
  71.                 Console.Write('*');
  72.                 Console.Write(new string('.', dotsMiddle));
  73.                 Console.Write('*');
  74.                 Console.WriteLine(new string('.', dotsEnds));
  75.                 dotsEnds++;
  76.                 dotsMiddle--;
  77.             }
  78.  
  79.             Console.Write(new string('.', dotsEnds));
  80.             Console.Write(new string('*', width - (dotsEnds * 2)));
  81.             Console.WriteLine(new string('.', dotsEnds));
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement