С# stringstream - C#
Формулировка задачи:
Доброго времени суток! Не могу разобраться с отличием синтаксиса с С++ и С#. Подскажите, пожалуйста, как в С# правильно написать вот такой кусочек кода?
stringstream Sp;
struct Set
{
vector <string> A;
void initialization()
{
int t=0;
for(int i=0; i<=9; i++)
for(int j=0; j<=9; j++)
if (i != j)
for(int k=0; k<=9; k++)
if (i != k && j!=k)
for(int z=0; z<=9; z++)
{
if (i != z && j != z && k != z)
{
Sp<<i<<j<<k<<z;
string a;
Sp>>a;
A.push_back(a);
Sp.clear();
}
}
}
Set CB;
CB.initialization();Решение задачи: «С# stringstream»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Cows
{
class Cows
{
static string str;
static string hod;
public static void Main()
{
Set CB = new Set();
CB.initialization();
Console.ReadKey();
}
struct Set
{
List<string> A;
public void initialization()
{
int t = 0;
for (int i = 0; i <= 9; i++)
for (int j = 0; j <= 9; j++)
if (i != j)
for (int k = 0; k <= 9; k++)
if (i != k && j != k)
for (int z = 0; z <= 9; z++)
{
if (i != z && j != z && k != z)
{
str = i.ToString() + j.ToString() + k.ToString() + z.ToString();
A.Add(str);
}
}
}
}
public static bool pos(char a, string b)
{
int n = b.Count();
for (int i = 0; i < n; i++)
if (b[i] == a) return true;
return false;
}
public static bool pr(string a, string hod, int bull, int cow)
{
int b = 0, c = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (i == j)
{
b += (hod[j] = a[i]);
}
else
{
c += (hod[j] == a[i]);
}
}
}
if(b!=bull || c!=cow)
return true;
return false;
}
public static void ot_hod(string hod, Set CB, List <string> A, int bull, int cow)
{
for (int i = 0; i < CB.A.size(); i++)
{
if (!CB.pr(CB.A[i], hod, bull, cow))
{
CB.A.erase(CB.A.begin() + i);
i--;
}
}
}
public static string v_hod(Set CB, List<string> A)
{
int n_max = 0, r_max = 0;
return CB.A[rand() % CB.A.size()];
}
}
}