Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace PageNumbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int digits = int.Parse(Console.ReadLine());
  14.             int sumOfDigits = 0;
  15.             int currentPage = 0;
  16.  
  17.             while (true)
  18.             {
  19.                 if (currentPage <= 9)
  20.                 {
  21.                     sumOfDigits++;                  
  22.                 }
  23.                 else if(currentPage >=10 && currentPage <= 99)
  24.                 {
  25.                     sumOfDigits += 2;
  26.                 }
  27.                 else if (currentPage >= 100 && currentPage <= 999)
  28.                 {
  29.                     sumOfDigits += 3;
  30.                 }
  31.                 else if (currentPage >= 1000 && currentPage <= 9999)
  32.                 {
  33.                     sumOfDigits += 4;
  34.                 }
  35.                 else if (currentPage >= 10000 && currentPage <= 99999)
  36.                 {
  37.                     sumOfDigits += 5;
  38.                 }
  39.                 else if (currentPage >= 100000 && currentPage <= 999999)
  40.                 {
  41.                     sumOfDigits += 6;
  42.                 }
  43.  
  44.                 currentPage++;
  45.  
  46.                 if (sumOfDigits >= digits)
  47.                 {
  48.                     break;
  49.                 }
  50.             }
  51.  
  52.             Console.WriteLine(currentPage-1);
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement