Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Soulstorm50/5ca088cc97bdebb1dbc017ae41fe6c52 to your computer and use it in GitHub Desktop.
Save Soulstorm50/5ca088cc97bdebb1dbc017ae41fe6c52 to your computer and use it in GitHub Desktop.
Между двумя девятками в числе Pi C#
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string s = "3,141592653589793238469";
Console.WriteLine("{0}", s);
int first = s.IndexOf('9'), second = first >= 0 ? s.IndexOf('9', first + 1) : -1;
int count = first != second && second >= 0 ? second - first - 1 : -1;
int three = second >= 0 ? s.IndexOf('9', second + 1) : -1;
int count2 = second != three && three >= 0 ? three - second - 1 : -1;
int four = three >= 0 ? s.IndexOf('9', three + 1) : -1;
int count3 = three != four && four >= 0 ? four - three - 1 : -1;
Console.WriteLine("между двумя девятками находятся {0} потом, {1} потом, {2} ", count, count2, count3);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment