Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Tickets2
- {
- static void Main()
- {
- //Telerik Academy
- //The winning tickets with 5 numbers of the lottery are those that have their middle numbers divided without remainder to their first and last number. The amount is the result of their division.
- //Ticket 11082. Middle number is: 108; first and last number are: 12. 108 / 12 = 9 so this is a winning ticket with amount to be paid 9.
- //The program should calculate the sum of the amounts to be paid and the number of the winning tickets.
- //The input will consist of a number of one ticket on each line. The last line will be 0 and will not be a ticket number.
- int winingTickets = 0,
- winningSum = 0;
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "0")
- {
- break;
- }
- else
- {
- char[] numbers = new char[input.Length];
- int i = 0;
- foreach (char item in input)
- {
- numbers[i] = item;
- i++;
- }
- string firstLast = Convert.ToString(numbers[0]) + numbers[input.Length - 1];
- string middleNum = Convert.ToString(numbers[1]);
- for (int j = 2; j < input.Length - 1; j++)
- {
- middleNum = middleNum + Convert.ToString(numbers[j]);
- }
- int result = Convert.ToInt32(middleNum) % Convert.ToInt32(firstLast);
- int amount = Convert.ToInt32(middleNum) / Convert.ToInt32(firstLast);
- if (result == 0)
- {
- winingTickets++;
- winningSum += amount;
- }
- }
- }
- Console.WriteLine(winningSum);
- Console.WriteLine(winingTickets);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment