Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. namespace BookOrders
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.     using System.Threading.Tasks;
  8.     using System.Threading;
  9.     using System.Globalization;
  10.     class BookOrders
  11.     {
  12.         static void Main()
  13.         {
  14.             Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  15.  
  16.             int n = int.Parse(Console.ReadLine());
  17.             var books = new List<double>();
  18.  
  19.             for (int i = 0; i < n*3; i++)
  20.             {
  21.                 books.Add(double.Parse(Console.ReadLine()));
  22.             }
  23.  
  24.             double totalBooks = 0;
  25.             double totalPrice = 0;
  26.  
  27.             for (int i = 0; i < books.Count; i+=3)
  28.             {
  29.                 double tempBooks = 0;
  30.                 double tempPrice = 0;
  31.                 double tempCost = 0;
  32.  
  33.                 tempBooks = books[i] * books[i + 1];
  34.                 tempCost = price(books, i, tempCost);
  35.  
  36.                 tempPrice = tempBooks * tempCost;
  37.                 totalPrice += tempPrice;
  38.                 tempPrice = 0;
  39.  
  40.                 totalBooks += tempBooks;
  41.                 tempBooks = 0;
  42.             }
  43.  
  44.             Console.WriteLine(totalBooks);
  45.             Console.WriteLine("{0:F2}", totalPrice);
  46.             Console.ReadLine();
  47.         }
  48.  
  49.         private static double price(List<double> books, int i, double tempCost)
  50.         {
  51.             if (books[i] >= 10 && books[i] <= 19)
  52.             {
  53.                 tempCost = (double)books[i + 2] - (double)0.5;
  54.             }
  55.             else if (books[i] >= 20 && books[i] <= 29)
  56.             {
  57.                 tempCost = (double)books[i + 2] - (double)0.6;
  58.             }
  59.             else if (books[i] >= 30 && books[i] <= 39)
  60.             {
  61.                 tempCost = (double)books[i + 2] - (double)0.7;
  62.             }
  63.             else if (books[i] >= 40 && books[i] <= 49)
  64.             {
  65.                 tempCost = (double)books[i + 2] - (double)0.8;
  66.             }
  67.             else if (books[i] >= 50 && books[i] <= 59)
  68.             {
  69.                 tempCost = (double)books[i + 2] - (double)0.9;
  70.             }
  71.             else if (books[i] >= 60 && books[i] <= 69)
  72.             {
  73.                 tempCost = (double)books[i + 2] - (double)1.0;
  74.             }
  75.             else if (books[i] >= 70 && books[i] <= 79)
  76.             {
  77.                 tempCost = (double)books[i + 2] - (double)1.1;
  78.             }
  79.             else if (books[i] >= 80 && books[i] <= 89)
  80.             {
  81.                 tempCost = (double)books[i + 2] - (double)1.2;
  82.             }
  83.             else if (books[i] >= 90 && books[i] <= 99)
  84.             {
  85.                 tempCost = (double)books[i + 2] - (double)1.3;
  86.             }
  87.             else if (books[i] >= 100 && books[i] <= 109)
  88.             {
  89.                 tempCost = (double)books[i + 2] - (double)1.4;
  90.             }
  91.             else
  92.             {
  93.                 tempCost = (double)books[i + 2] - (double)1.5;
  94.             }
  95.             return tempCost;
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement