{"id":268358,"date":"2015-11-17T12:57:06","date_gmt":"2015-11-17T09:57:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=268358"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=268358","title":{"rendered":"LINQ \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 \u0440\u0438\u043c\u0441\u043a\u0438\u043c\u0438 \u0438 \u0430\u0440\u0430\u0431\u0441\u043a\u0438\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438"},"content":{"rendered":"<p>       \u0421\u043b\u043e\u0436\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b \u0441\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430\u043c\u0438 LINQ, \u0430 \u0441\u043e \u0448\u043a\u043e\u043b\u044c\u043d\u0438\u043a\u0430\u043c\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0440\u0438\u043c\u0441\u043a\u043e\u0439 \u0438 \u0430\u0440\u0430\u0431\u0441\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0412 \u0438\u0442\u043e\u0433\u0435, \u043c\u044b\u0441\u043b\u0438 \u0437\u0430\u043f\u043b\u0435\u043b\u0438\u0441\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0436\u0430\u043b\u043a\u043e \u0441\u0445\u043e\u0440\u043e\u043d\u0438\u0442\u044c \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0440\u0445\u0438\u0432\u0430\u0445. \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f LINQ.<\/p>\n<p>  \u0418 \u0442\u0430\u043a, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0438\u043c\u0441\u043a\u0438\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u0430\u0440\u0430\u0431\u0441\u043a\u0438\u043c\u0438.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"cs\">Dictionary&lt;int, string&gt; ra = new Dictionary&lt;int, string&gt;         { { 1000, &quot;M&quot; },  { 900, &quot;CM&quot; },  { 500, &quot;D&quot; },  { 400, &quot;CD&quot; },  { 100, &quot;C&quot; },                           { 90 , &quot;XC&quot; },  { 50 , &quot;L&quot; },  { 40 , &quot;XL&quot; },  { 10 , &quot;X&quot; },                           { 9  , &quot;IX&quot; },  { 5  , &quot;V&quot; },  { 4  , &quot;IV&quot; },  { 1  , &quot;I&quot; } }; <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u043e\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u043e\u0440\u044b \u0438\u0437 \u0440\u0438\u043c\u0441\u043a\u043e\u0439 \u0432 \u0430\u0440\u0430\u0431\u0441\u043a\u0443\u044e \u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e. \u0414\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438 \u0438 \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0443\u0441\u043b\u043e\u0432\u0438\u044f. \u0414\u043b\u044f \u0430\u0440\u0430\u0431\u0441\u043a\u0438\u0445 \u0446\u0438\u0444\u0440 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0439 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043a\u0430\u043a [1,4000). \u0410 \u0440\u0438\u043c\u0441\u043a\u0438\u0435 \u0446\u0438\u0444\u0440\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c\u0438 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u043a \u0432\u0435\u0440\u0445\u043d\u0435\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443.<\/p>\n<h4> \u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0438\u0437 \u0430\u0440\u0430\u0431\u0441\u043a\u0438\u0445 \u0432 \u0440\u0438\u043c\u0441\u043a\u0438\u0435 <\/h4>\n<p>  \u0420\u0430\u0437\u0431\u043e\u0440 \u0447\u0438\u0441\u043b\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0447\u0438\u0441\u0435\u043b. \u041a\u043b\u044e\u0447\u0438 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u044b \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f. \u041f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0438\u0445 \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043b\u044e\u0447 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 (\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 Where). \u0412 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u044d\u0442\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 \u0438\u0437 \u0440\u0438\u043c\u0441\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0421\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 \u0441 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c \u0447\u0438\u0441\u043b\u0430 (\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 Select). \u041f\u0435\u0440\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u043e\u043c\u044b\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0447\u0438\u0441\u043b\u0430 \u0432 \u0440\u0438\u043c\u0441\u043a\u043e\u0439 \u043d\u043e\u0442\u0430\u0446\u0438\u0438 (\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 FirstOrDefault).<\/p>\n<pre><code class=\"cs\">string ToRoman(int number) =&gt; ra             .Where(d =&gt; number &gt;= d.Key)             .Select(d =&gt; d.Value + ToRoman(number - d.Key))             .FirstOrDefault(); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0438\u0437 \u0440\u0438\u043c\u0441\u043a\u0438\u0445 \u0432 \u0430\u0440\u0430\u0431\u0441\u043a\u0438\u0435 <\/h4>\n<p>  \u0420\u0430\u0437\u0431\u043e\u0440 \u0440\u0438\u043c\u0441\u043a\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e. \u041f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u0438\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u043d\u0430 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 number.StartsWith(d.Value). \u041f\u0440\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0435 \u043a\u043b\u044e\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0431\u0443\u043a\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044e. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0439 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0439.<\/p>\n<pre><code class=\"cs\">int ToArabic(string number) =&gt; number.Length == 0 ? 0 : ra             .Where(d =&gt; number.StartsWith(d.Value))             .Select(d =&gt; d.Key + ToArabic(number.Substring(d.Value.Length)))             .FirstOrDefault(); <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043d\u0433\u0430 v1<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">static class RomanNum {     \/\/ (c) 2015, Alexey Danov | THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY ...     static Dictionary&lt;int, string&gt; ra = new Dictionary&lt;int, string&gt;     { { 1000, &quot;M&quot; },  { 900, &quot;CM&quot; },  { 500, &quot;D&quot; },  { 400, &quot;CD&quot; },  { 100, &quot;C&quot; },                       { 90 , &quot;XC&quot; },  { 50 , &quot;L&quot; },  { 40 , &quot;XL&quot; },  { 10 , &quot;X&quot; },                       { 9  , &quot;IX&quot; },  { 5  , &quot;V&quot; },  { 4  , &quot;IV&quot; },  { 1  , &quot;I&quot; } };      public static string ToRoman(int number) =&gt; ra         .Where(d =&gt; number &gt;= d.Key)         .Select(d =&gt; d.Value + ToRoman(number - d.Key))         .FirstOrDefault();      public static int ToArabic(string number) =&gt; number.Length == 0 ? 0 : ra         .Where(d =&gt; number.StartsWith(d.Value))         .Select(d =&gt; d.Key + ToArabic(number.Substring(d.Value.Length)))         .First(); } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f. \u041d\u043e \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u043e 499 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u044f\u0442\u044c\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438: CDXCIX, LDVLIV, XDIX, VDIV \u0438\u043b\u0438 ID. \u0414\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f. \u041c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0431\u0443\u043a\u0432 IVXLCDM, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0447\u0438\u0441\u043b\u0430 (1,5,10,50,100,500,1000).<\/p>\n<p>  \u0412 \u0446\u0435\u043b\u044f\u0445 \u043f\u0440\u043e\u043a\u0430\u0447\u043a\u0438 \u043d\u0430\u0432\u044b\u043a\u043e\u0432 .Net \u043c\u0430\u0433\u0430 VC-\u0443\u0440\u043e\u0432\u043d\u044f (VC == 95), \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0410 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430\u0432\u044b\u043a\u043e\u0432 \u0447\u0442\u0435\u043d\u0438\u044f \u0447\u0443\u0436\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 \u0432\u0441\u0442\u0443\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u044f\u0445 \u0432 \u0448\u043a\u043e\u043b\u0443 .Net \u043c\u0430\u0433\u043e\u0432 IC-\u0443\u0440\u043e\u0432\u043d\u044f. <\/p>\n<h4>\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0438\u0437 \u0440\u0438\u043c\u0441\u043a\u0438\u0445 \u0432 \u0430\u0440\u0430\u0431\u0441\u043a\u0438\u0435 \u0441 \u043e\u0431\u0432\u044f\u0437\u043a\u043e\u0439<\/h4>\n<p>  \u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0414\u0430\u043b\u0435\u0435 \u043a\u043e\u0434 \u0431\u0435\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<pre><code class=\"cs\">int o = 1; string w = &quot;IVXLCDM&quot;; Dictionary&lt;char, int&gt; ra = w.ToDictionary(ch =&gt; ch, ch =&gt; (o = (&quot;&quot; + o)[0] == '1' ? o * 2 : o * 5) \/ 2); int ToArabic(string num) =&gt;      num.Select((c, i) =&gt; ++i &lt; num.Length && ra[c] &lt; ra[num[i]] ? -ra[c] : ra[c]).Sum(); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0438\u0437 \u0430\u0440\u0430\u0431\u0441\u043a\u0438\u0445 \u0432 \u0440\u0438\u043c\u0441\u043a\u0438\u0435 \u0441 \u043e\u0431\u0432\u044f\u0437\u043a\u043e\u0439<\/h4>\n<p>  \u0410 \u0432\u043e\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0432 \u0440\u0438\u043c\u0441\u043a\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043f\u0430\u0440\u0430 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u041c\u043e\u0436\u043d\u043e \u0438\u0445 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"cs\">string W(int k, int l = 1) =&gt; w.Substring(k, l); string R(char m, int k) =&gt;      m == '9' ? W(k-2)+W(k) : m == '5' ? W(k-1) : m == '4' ? W(k-2, 2) : W(k-2);  string ToRoman(int num) =&gt; num &lt; 1 ? &quot;&quot; :         (from z in &quot;000100101&quot;.Split('1') from m in &quot;9541&quot; select m + z)        .Where(z =&gt; num &gt;= (o = int.Parse(z)))        .Select(z =&gt; R(z[0], z.Length * 2)).First() + ToRoman(num - o); <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043d\u0433\u0430 v2<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">static class RomanNumEx {     \/\/ (c) 2015, Alexey Danov | THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY ...     static int o = 1;     static string w = &quot;IVXLCDM&quot;;     static Dictionary&lt;char, int&gt; ra = w.ToDictionary(ch =&gt; ch, ch =&gt; (o = (&quot;&quot; + o)[0] == '1' ? o * 2 : o * 5) \/ 2);      public static int ToArabic(string num) =&gt; num         .Select((c, i) =&gt; ++i &lt; num.Length && ra[c] &lt; ra[num[i]] ? -ra[c] : ra[c]).Sum();      static string W(int k, int l = 1) =&gt; w.Substring(k, l);     static string R(char m, int k) =&gt; m == '9' ? W(k-2)+W(k) : m == '5' ? W(k-1) : m == '4' ? W(k-2, 2) : W(k-2);      public static string ToRoman(int num) =&gt; num &lt; 1 ? &quot;&quot; :          (from z in &quot;000100101&quot;.Split('1') from m in &quot;9541&quot; select m + z)         .Where(z =&gt; num &gt;= (o = int.Parse(z)))         .Select(z =&gt; R(z[0], z.Length * 2)).First() + ToRoman(num - o); } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u042d\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b \u043f\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b, \u043d\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0418 \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u0432 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043c LINQ.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/271035\/\"> http:\/\/habrahabr.ru\/post\/271035\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0421\u043b\u043e\u0436\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b \u0441\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430\u043c\u0438 LINQ, \u0430 \u0441\u043e \u0448\u043a\u043e\u043b\u044c\u043d\u0438\u043a\u0430\u043c\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0440\u0438\u043c\u0441\u043a\u043e\u0439 \u0438 \u0430\u0440\u0430\u0431\u0441\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0412 \u0438\u0442\u043e\u0433\u0435, \u043c\u044b\u0441\u043b\u0438 \u0437\u0430\u043f\u043b\u0435\u043b\u0438\u0441\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0436\u0430\u043b\u043a\u043e \u0441\u0445\u043e\u0440\u043e\u043d\u0438\u0442\u044c \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0440\u0445\u0438\u0432\u0430\u0445. \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f LINQ.<\/p>\n<p>  \u0418 \u0442\u0430\u043a, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0438\u043c\u0441\u043a\u0438\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u0430\u0440\u0430\u0431\u0441\u043a\u0438\u043c\u0438.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-268358","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/268358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268358"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/268358\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}