یه تایپیک تو همین سایت در مورد زبان D دیدم و ازش خوشم اومد. سینتکس راحتتری نسبت به C++ داره و جمعآوری حافظه رو خودش انجام میده. میخواستم نظرتون رو در موردش بدونم و چندتا سوال؟جواب هیچکدوم از سوالهات رو نمیدونم، چون من برنامهنویس نیستم. ولی دیشب اولین برنامهام به زبان D رو نوشتم که برنامه وزیرهای شطرنج بود. اولین چیزی که به نظرم جالب بود اینه که آرایهها رو میشه پویا تعریف کرد (یعنی در زمان اجرا سایزشون رو تغییر داد). این کار به نظرم در C++ قابل انجام نیست و برای کار مشابه باید مثلا از بردارها استفاده کرد. برنامه در زیر آورده شده.
آیا میشه از کتابخانههای زبان C تو این زبان استفاده کرد؟
چه فریمورکهایی واسه این زبان وجود داره؟
پشتیبانیه فریمورک Qt از این زبان در چه حده؟
دلیل عدم محبوبیتش چیه؟
ممنون از جواباتون
import std.stdio, std.math;
bool hit (ushort[] propose, ushort col){//The hit function checks if the queen in the $col$-th column hits any queens in previous columns ($0...col-1$).
foreach (i; 0..col)
if (propose[col]-propose[i]==0 || abs(propose[col]-propose[i])==col-i) return true;
return false;
}
int main() {
ulong counter;
ushort numberofqueens;
ushort row;
ushort column;
writeln("This D program solves the Queen Problem for any number of queens by backtraking. Any solution is of the form (for example)\n92\t[8, 4, 1, 3, 6, 2, 7, 5]\nwhere 92 is the counter and the array means that queens in columns 1 and 2 are located in rows 8 and 4, respectively.\nPlease enter the number of queens:");
readf("%s", &numberofqueens);
ushort[] board = new ushort[numberofqueens];
if (numberofqueens == 1) {writeln(1,"\t",board); return 0;}
while (column < numberofqueens) {
while (row <= numberofqueens){
row++;
board[column] = row;
if (!hit(board,column)) {
if (column == numberofqueens-1) {//then current queen is a solution
counter++; writefln("%s\t%s",counter,board);//writing the solution
if (row == numberofqueens) column--;//if the last queen is at the last row, we need to backtrack
row = board[column];//and continue
}
else {//we need to go to the next column and start from row 0
row = 0;
column++;
break;
}
}
else {//when hit(board,column)
if (row == numberofqueens) {//we reached the last row, so we must backtrack
column--;
if (board[column] == numberofqueens) {//if the previous queen is also at the last row, we need to backtrack again (if possible) else we are done
if (column > 0) column--;
else return 0;
}
row = board[column];//now we need to find the row of the previous queen again
break;
}
}
}//end of while row
}//end of while column
return 1;
}
این کار به نظرم در C++ قابل انجام نیست
type *name;
name = new type[ Your Number ];
int* a = NULL; .
int n;
cin >> n;
a = new int[n];
سی ++ یخورده دیگه چیز شده.
جاوا رو همیشه ترجیح میدادم.راجع به D هم چیزی نمیدونم :oops: