class Program
{
static void Main(string[] args)
string src = " Qwy. ... Asdf.. Lkjdfs A.";
//string dest = ReplaceDots(src, '.', '…', 3);
string dest = ReplaceDots(src, '.', "...", 3);
Console.WriteLine("src:\t" + src);
Console.WriteLine("dest:\t" + dest);
Console.WriteLine();
Console.Write("Press any key for exit ...");
Console.ReadKey(true);
}
//private static string ReplaceDots(string src, char dotCh, char dots, int minDotsCount)
private static string ReplaceDots(string src, char dotCh, string dots, int minDotsCount)
StringBuilder dest = new StringBuilder();
int i = 0;
while (i < src.Length)
int dotsCount = 0;
while (i < src.Length && src[i] == dotCh)
dotsCount++;
i++;
if (dotsCount >= minDotsCount)
dest.Append(dots);
else if (dotsCount == 0)
dest.Append(src[i++]);
else
while (dotsCount-- > 0)
dest.Append(dotCh);
return dest.ToString(); ;
#include <iomanip>
using namespace std;
int main() {
int n,k,m;
cout<<"N = "; cin>>n;
cout<<endl;
if (n%2!=0) {
cout<<"недопустимое значение N: "<<n<<endl;
return(1);
}
cout<<setw(12)<<"gooses"<<setw(10)<<"rabbits"<<endl;
m=n/4; k=(n-m*4)/2;
while (m>=0) {
if (k>0) cout<<setw(10)<<k;
else cout<<setw(10)<<"--";
if (m>0) cout<<setw(10)<<m;
else cout<<setw(10)<<"--";
cout<<endl;
m--; k+=2;
}
system("pause");
return(0);
}
class Program
{
static void Main(string[] args)
{
string src = " Qwy. ... Asdf.. Lkjdfs A.";
//string dest = ReplaceDots(src, '.', '…', 3);
string dest = ReplaceDots(src, '.', "...", 3);
Console.WriteLine("src:\t" + src);
Console.WriteLine("dest:\t" + dest);
Console.WriteLine();
Console.Write("Press any key for exit ...");
Console.ReadKey(true);
}
//private static string ReplaceDots(string src, char dotCh, char dots, int minDotsCount)
private static string ReplaceDots(string src, char dotCh, string dots, int minDotsCount)
{
StringBuilder dest = new StringBuilder();
int i = 0;
while (i < src.Length)
{
int dotsCount = 0;
while (i < src.Length && src[i] == dotCh)
{
dotsCount++;
i++;
}
if (dotsCount >= minDotsCount)
dest.Append(dots);
else if (dotsCount == 0)
dest.Append(src[i++]);
else
while (dotsCount-- > 0)
dest.Append(dotCh);
}
return dest.ToString(); ;
}
}