Advertisement
EmoRz

CheckDataFromEGN_1.1

May 26th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace EGN
  6. {
  7.     class Program
  8.     {
  9.         private static long CalculateYears(long n)
  10.         {
  11.             //ПО месеца се разбира коя година (<1900||1900<=1999||>1999) е роден човека
  12.             //+20
  13.             //+40
  14.             var month = 0;
  15.             var temp = n;
  16.             if (n<12)
  17.             {
  18.                 for (int i = 1; i <= n; i++)
  19.                 {
  20.                     if (i == temp)
  21.                     {
  22.                         month = i;
  23.                         break;
  24.                     }
  25.                 }
  26.             }
  27.             if (n>21 && n <= 32)
  28.             {
  29.                 for (int i = 21; i <= n; i++)
  30.                 {
  31.                     var minusTwenty = i - 20;
  32.  
  33.                     if (i == temp)
  34.                     {
  35.                         month = minusTwenty;
  36.                         break;
  37.                     }
  38.                 }
  39.             }
  40.             if (n>=41 && n<=52)
  41.             {
  42.                 for (int i = 41; i <= n; i++)
  43.                 {
  44.                     var minusFourty = i - 40;
  45.                     if (i == temp)
  46.                     {
  47.                         month = minusFourty;
  48.                         break;
  49.                     }
  50.                 }
  51.             }
  52.             return month;
  53.  
  54.         }
  55.         static void Main(string[] args)
  56.         {
  57.             long input = long.Parse(Console.ReadLine());
  58.            
  59.             long result = 0;
  60.             long res = 0;
  61.             long newTemp = input;
  62.             long temporal = 0;
  63.             long tre = input;
  64.             for (int j = 0; j < 5; j++)
  65.             {
  66.                 temporal = tre % 100;
  67.                 tre /= 100;
  68.             }
  69.             //0044285021
  70.             if (temporal!=0)
  71.             {
  72.                 List<long> egnn = new List<long>();
  73.                 List<long> controlNumber = new List<long>();
  74.                 while (newTemp > 0)
  75.                 {
  76.                     res = newTemp % 10;
  77.                     controlNumber.Add(res);
  78.                     newTemp /= 10;
  79.                 }
  80.                 long[] cont = { 0, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
  81.                 long contrMulty = 0;
  82.                 for (int i = 1; i < controlNumber.Count; i++)
  83.                 {
  84.                     contrMulty += (cont[i] * controlNumber[i]);
  85.                 }
  86.                 long controla = 0;
  87.                 if (contrMulty % 11 == 10)
  88.                 {
  89.                     controla = 0;
  90.                 }
  91.                 else
  92.                 {
  93.                     controla = contrMulty % 11;
  94.                 }
  95.  
  96.                 Console.WriteLine("Контролно число: " + controla);
  97.                 Console.Write("Роден:");
  98.                 while (input > 0)
  99.                 {
  100.                     result = input % 100;
  101.                     egnn.Add(result);
  102.                     input /= 100;
  103.                 }
  104.                 var checkForYear = egnn[3];
  105.                 //
  106.                 var year = CalculateYearsPeint(egnn);
  107.                 Console.WriteLine(year);
  108.                 Console.WriteLine($"Възраст/разлика м/у датите в години: {DateTime.Now.Year} => {DateTime.Now.Year - year}");
  109.                 //
  110.                 var month = CalculateYears(egnn[3]);
  111.                 Console.Write("Month: ");
  112.                 switch (month)
  113.                 {
  114.                     case 1: Console.WriteLine("Jan"); break;
  115.                     case 2: Console.WriteLine("Feb"); break;
  116.                     case 3: Console.WriteLine("March"); break;
  117.                     case 4: Console.WriteLine("April"); break;
  118.                     case 5: Console.WriteLine("May"); break;
  119.                     case 6: Console.WriteLine("June"); break;
  120.                     case 7: Console.WriteLine("July"); break;
  121.                     case 8: Console.WriteLine("August"); break;
  122.                     case 9: Console.WriteLine("Sept"); break;
  123.                     case 10: Console.WriteLine("Oct"); break;
  124.                     case 11: Console.WriteLine("Novem"); break;
  125.                     case 12: Console.WriteLine("Dec"); break;
  126.                 }
  127.                 if (egnn[2] > 0 && egnn[2] < 32)
  128.                 {
  129.                     var sufix = "Ден: ";
  130.  
  131.                     Console.WriteLine(sufix + egnn[2]);
  132.                 }
  133.                 var sexcontrol = egnn[0] / 10;
  134.                 if (sexcontrol % 2 == 0)
  135.                 {
  136.                     Console.WriteLine("Пол: Мъж");
  137.                 }
  138.                 else
  139.                 {
  140.                     Console.WriteLine("Пол: Жена");
  141.                 }
  142.             }
  143.             else
  144.             {
  145.                 List<long> egnn = new List<long>();
  146.                 List<long> controlNumber = new List<long>();
  147.                 while (newTemp > 0)
  148.                 {
  149.                     res = newTemp % 10;
  150.                     controlNumber.Add(res);
  151.                     newTemp /= 10;
  152.                 }
  153.                 long[] cont = { 0, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
  154.                 long contrMulty = 0;
  155.                 for (int i = 1; i < controlNumber.Count; i++)
  156.                 {
  157.                     contrMulty += (cont[i] * controlNumber[i]);
  158.                 }
  159.                 long controla = 0;
  160.                 if (contrMulty % 11 == 10)
  161.                 {
  162.                     controla = 0;
  163.                 }
  164.                 else
  165.                 {
  166.                     controla = contrMulty % 11;
  167.                 }
  168.  
  169.                 Console.WriteLine("Контролно число: " + controla);
  170.                 Console.Write("Роден:");
  171.                 while (input > 2)
  172.                 {
  173.                     result = input % 100;
  174.                     egnn.Add(result);
  175.                     input /= 100;
  176.                 }
  177.                var year = TryCalcYear(egnn);
  178.                 Console.WriteLine(year);
  179.                
  180.                 Console.WriteLine($"Възраст/разлика м/у датите в години: {DateTime.Now.Year} => {DateTime.Now.Year - year}");
  181.                 var month = CalculateYears(egnn[3]);
  182.                 Console.Write("Month: ");
  183.                 switch (month)
  184.                 {
  185.                     case 1: Console.WriteLine("Jan"); break;
  186.                     case 2: Console.WriteLine("Feb"); break;
  187.                     case 3: Console.WriteLine("March"); break;
  188.                     case 4: Console.WriteLine("April"); break;
  189.                     case 5: Console.WriteLine("May"); break;
  190.                     case 6: Console.WriteLine("June"); break;
  191.                     case 7: Console.WriteLine("July"); break;
  192.                     case 8: Console.WriteLine("August"); break;
  193.                     case 9: Console.WriteLine("Sept"); break;
  194.                     case 10: Console.WriteLine("Oct"); break;
  195.                     case 11: Console.WriteLine("Novem"); break;
  196.                     case 12: Console.WriteLine("Dec"); break;
  197.                 }
  198.                 if (egnn[2] > 0 && egnn[2] < 32)
  199.                 {
  200.                     var sufix = "Ден: ";
  201.  
  202.                     Console.WriteLine(sufix + egnn[2]);
  203.                 }
  204.                 var sexcontrol = egnn[0] / 10;
  205.                 if (sexcontrol % 2 == 0)
  206.                 {
  207.                     Console.WriteLine("Пол: Мъж");
  208.                 }
  209.                 else
  210.                 {
  211.                     Console.WriteLine("Пол: Жена");
  212.                 }
  213.             }
  214.             Console.WriteLine(DateTime.Now.Year);
  215.         }
  216.  
  217.         private static int TryCalcYear(List<long> egnn)
  218.         {
  219.             var checkForYear = egnn[3];
  220.             var years = 0;
  221.             if (checkForYear > 21 && checkForYear <= 32)
  222.             {
  223.                 years += 1800;
  224.                // Console.WriteLine(years);
  225.             }
  226.             else if (checkForYear >= 41 && checkForYear <= 52)
  227.             {
  228.                 years += 2000;
  229.                // Console.WriteLine(years);
  230.             }
  231.             else
  232.             {
  233.                 years += 1900;
  234.                 //Console.WriteLine(years);
  235.             }
  236.             return years;
  237.         }
  238.  
  239.         private static long CalculateYearsPeint(List<long> egnn)
  240.         {
  241.             var checkForYear = egnn[3];
  242.             if (checkForYear > 21 && checkForYear <= 32)
  243.             {
  244.                 egnn[4] += 1800;
  245.                // Console.WriteLine(egnn[4]);
  246.             }
  247.             else if (checkForYear >= 41 && checkForYear <= 52)
  248.             {
  249.                 egnn[4] += 2000;
  250.                 //Console.WriteLine(egnn[4]);
  251.             }
  252.             else
  253.             {
  254.                 egnn[4] += 1900;
  255.                 //Console.WriteLine(egnn[4]);
  256.             }
  257.             return egnn[4];
  258.         }
  259.     }
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement