У меня есть набор координат решетки в файле с именем «Lattice.txt». Мой код ниже проверить количество соседа для каждого из решеточногоПодсчитайте количество решетки с таким же количеством соседней решетки
void CheckLattice(int b)
{
vector<Lattice> lattices;
/* reading from file logic */
ifstream theFile("Lattice.txt");
double x1,y1,x2,y2;
while (theFile >> x1 >> y1 >> x2 >> y2) {
lattices.push_back(Lattice(x1,y1, x2,y2));
}
/* counting neighbors logic */
int lattice_count = 0;
int GroupLattice=0;
for (int x = 0; x < lattices.size(); ++x) {
if (lattices[b].NearestLattice(lattices[x])) {
if (x==b) {
continue; //this is our lattice , skip it.
}
lattice_count++;
}
GroupLattice++;
}
cout<<"Lattice "<<(b+1)<<" has = "<<lattice_count<<" neighbours "<<endl;
cout << " The number of lattice with "<< lattice_count << " neighbours are " << GroupLattice << endl;
cout << endl;
}
int main()
{
int neighbour=0;
for(int i=0; i<10; i++){
CheckLattice(i);
}
return 0;
}
Он возвращает значение как this-
Lattice 1 has = 7 neighbours The number of lattice with 7 neighbours are 14 Lattice 2 has = 3 neighbours The number of lattice with 3 neighbours are 15 Lattice 3 has = 8 neighbours The number of lattice with 8 neighbours are 14 Lattice 4 has = 6 neighbours The number of lattice with 6 neighbours are 15 Lattice 5 has = 8 neighbours The number of lattice with 8 neighbours are 14 Lattice 6 has = 8 neighbours The number of lattice with 8 neighbours are 15 Lattice 7 has = 8 neighbours The number of lattice with 8 neighbours are 14 Lattice 8 has = 1 neighbours The number of lattice with 1 neighbours are 15 Lattice 9 has = 7 neighbours The number of lattice with 7 neighbours are 14 Lattice 10 has = 5 neighbours The number of lattice with 5 neighbours are 15
Хотя этот код возвращает число соседних для каждого правильной решетки, не возвращает значение общего количества решетки с одинаковым количеством соседних. Вместо этого это только возврат 14 или 15! Как я могу это исправить?
Я хочу, чтобы на выходе что-то вроде this-
Lattice 1 has = 7 neighbours Lattice 2 has = 3 neighbours Lattice 3 has = 8 neighbours Lattice 4 has = 6 neighbours Lattice 5 has = 8 neighbours Lattice 6 has = 8 neighbours Lattice 7 has = 8 neighbours Lattice 8 has = 1 neighbours Lattice 9 has = 7 neighbours Lattice 10 has = 5 neighbours The number of lattice with 1 neighbours are 1 The number of lattice with 2 neighbours are 1 The number of lattice with 7 neighbours are 2 The number of lattice with 8 neighbours are 4 ...etc
я мог бы что-то пропустил. Может ли кто-нибудь помочь мне в этом?
Я думаю, что он означает точки решетки в твердом кристалле. –
@huseyintugrulbuyukisik: Вы правы. Я имею в виду [точки решетки] (http://en.wikipedia.org/wiki/Crystal_structure) – aries0152
, почему вы читаете файл 10 раз? –